IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
IKVM.Runtime.JNI.JNIFrame Struct Reference

Public Member Functions

nint Enter (object callerID)
 Enters the JNIFrame with a specified ikvm.@internal.CallerID in scope.
 
readonly void Leave ()
 Leaves a JNIFrame previously entered.
 
readonly nint MakeLocalRef (object obj)
 
readonly object UnwrapLocalRef (nint p)
 

Static Public Member Functions

static nint GetFuncPtr (object callerID, string clazz, string name, string sig)
 Invoked by managed code to acquire a function pointer to a native JNI method.
 
static string JniMangle (string name)
 

Public Attributes

JNIEnvContext env
 
JNIEnvContext.FrameState prevFrameState
 

Detailed Description

Definition at line 31 of file JNIFrame.cs.

Member Function Documentation

◆ Enter()

nint IKVM.Runtime.JNI.JNIFrame.Enter ( object callerID)

Enters the JNIFrame with a specified ikvm.@internal.CallerID in scope.

Parameters
callerID
Returns

Definition at line 191 of file JNIFrame.cs.

192 {
193#if FIRST_PASS || IMPORTER || EXPORTER
194 throw new NotImplementedException();
195#else
196 env = JNIEnvContext.Current ?? JNIEnv.CreateJNIEnv(JVM.Context)->GetContext();
197 prevFrameState = env.Enter((ikvm.@internal.CallerID)callerID);
198 return (nint)(void*)env.pJNIEnv;
199#endif
200 }
JNIEnvContext.FrameState prevFrameState
Definition JNIFrame.cs:151

◆ GetFuncPtr()

static nint IKVM.Runtime.JNI.JNIFrame.GetFuncPtr ( object callerID,
string clazz,
string name,
string sig )
static

Invoked by managed code to acquire a function pointer to a native JNI method.

Parameters
callerID
clazz
name
sig
Returns
Exceptions
java.lang.UnsatisfiedLinkError

Definition at line 43 of file JNIFrame.cs.

44 {
45#if FIRST_PASS || IMPORTER || EXPORTER
46 throw new NotImplementedException();
47#else
48 var loader = RuntimeClassLoader.FromCallerID((ikvm.@internal.CallerID)callerID);
49 var argl = sizeof(nint) + sizeof(nint);
50 for (int i = 1; sig[i] != ')'; i++)
51 {
52 switch (sig[i])
53 {
54 case '[':
55 argl += sizeof(nint);
56 while (sig[++i] == '[') ;
57 if (sig[i] == 'L')
58 while (sig[++i] != ';') ;
59 break;
60 case 'L':
61 argl += sizeof(nint);
62 while (sig[++i] != ';') ;
63 break;
64 case 'J':
65 case 'D':
66 argl += 8;
67 break;
68 case 'F':
69 case 'I':
70 case 'C':
71 case 'Z':
72 case 'S':
73 case 'B':
74 argl += 4;
75 break;
76 default:
77 Debug.Assert(false);
78 break;
79 }
80 }
81
82 var mangledClass = JniMangle(clazz);
83 var mangledName = JniMangle(name);
84 var mangledSig = JniMangle(sig.Substring(1, sig.IndexOf(')') - 1));
85 var methodName = $"Java_{mangledClass}_{mangledName}";
86 var longMethodName = $"Java_{mangledClass}_{mangledName}__{mangledSig}";
87 JVM.Context.Diagnostics.GenericJniInfo($"Linking native method: {clazz}.{name}{sig}, classLoader = {loader}, methodName = {methodName}, longMethodName = {longMethodName}, argl = {argl}");
88
89 lock (JNINativeLoader.SyncRoot)
90 {
91 foreach (var p in loader.GetNativeLibraries())
92 {
93 if (LibJvm.Instance.JVM_FindLibraryEntry(p, NativeLibrary.MangleExportName(methodName, argl)) is nint h1 and not 0)
94 {
95 JVM.Context.Diagnostics.GenericJniInfo($"Native method {clazz}.{name}{sig} found in library 0x{p:X} (short)");
96 return h1;
97 }
98
99 if (LibJvm.Instance.JVM_FindLibraryEntry(p, NativeLibrary.MangleExportName(longMethodName, argl)) is nint h2 and not 0)
100 {
101 JVM.Context.Diagnostics.GenericJniInfo($"Native method {clazz}.{name}{sig} found in library 0x{p:X} (long)");
102 return h2;
103 }
104 }
105 }
106
107 var msg = $"{clazz}.{name}{sig}";
108 JVM.Context.Diagnostics.GenericJniError($"UnsatisfiedLinkError: {msg}");
109 throw new java.lang.UnsatisfiedLinkError(msg);
110#endif
111 }
static string JniMangle(string name)
Definition JNIFrame.cs:113

◆ JniMangle()

static string IKVM.Runtime.JNI.JNIFrame.JniMangle ( string name)
static

Definition at line 113 of file JNIFrame.cs.

114 {
115 var sb = new ValueStringBuilder(name.Length + 8);
116
117 foreach (var c in name)
118 {
119 switch (c)
120 {
121 case '/':
122 sb.Append('_');
123 break;
124 case '_':
125 sb.Append("_1");
126 break;
127 case ';':
128 sb.Append("_2");
129 break;
130 case '[':
131 sb.Append("_3");
132 break;
133 case >= '0' and <= '9':
134 case >= 'a' and <= 'z':
135 case >= 'A' and <= 'Z':
136 sb.Append(c);
137 break;
138 default:
139 sb.Append($"_0{(int)c:x4}");
140 break;
141 }
142 }
143
144 return sb.ToString();
145 }

◆ Leave()

readonly void IKVM.Runtime.JNI.JNIFrame.Leave ( )

Leaves a JNIFrame previously entered.

Definition at line 205 of file JNIFrame.cs.

206 {
207#if FIRST_PASS || IMPORTER || EXPORTER
208 throw new NotImplementedException();
209#else
210 env.Leave(prevFrameState);
211 JVM.ThrowPendingException();
212#endif
213 }

◆ MakeLocalRef()

readonly nint IKVM.Runtime.JNI.JNIFrame.MakeLocalRef ( object obj)

Definition at line 215 of file JNIFrame.cs.

216 {
217#if FIRST_PASS || IMPORTER || EXPORTER
218 throw new NotImplementedException();
219#else
220 return env.MakeLocalRef(obj);
221#endif
222 }

◆ UnwrapLocalRef()

readonly object IKVM.Runtime.JNI.JNIFrame.UnwrapLocalRef ( nint p)

Definition at line 224 of file JNIFrame.cs.

225 {
226#if FIRST_PASS || IMPORTER || EXPORTER
227 throw new NotImplementedException();
228#else
229 return JNIEnv.UnwrapRef(env, p);
230#endif
231 }

Member Data Documentation

◆ env

JNIEnvContext IKVM.Runtime.JNI.JNIFrame.env

Definition at line 150 of file JNIFrame.cs.

◆ prevFrameState

JNIEnvContext.FrameState IKVM.Runtime.JNI.JNIFrame.prevFrameState

Definition at line 151 of file JNIFrame.cs.


The documentation for this struct was generated from the following file: