Skip to content

Commit

Permalink
Tidy up and add special/hot path for getting JNI ref 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Rogers committed Jun 6, 2009
1 parent c9019db commit e923bf0
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions rvm/src/org/jikesrvm/jni/JNIEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.jikesrvm.mm.mminterface.MemoryManager;
import org.jikesrvm.classloader.RVMMethod;
import org.jikesrvm.compilers.common.CompiledMethods;
import org.jikesrvm.runtime.BootRecord;
import org.jikesrvm.runtime.Magic;
import org.jikesrvm.runtime.RuntimeEntrypoints;
import org.jikesrvm.scheduler.RVMThread;
Expand Down Expand Up @@ -54,6 +55,7 @@ public final class JNIEnvironment implements SizeConstants {
* This is the shared JNI function table used by native code
* to invoke methods in @link{JNIFunctions}.
*/
@Untraced
public static FunctionTable JNIFunctions;

/**
Expand Down Expand Up @@ -314,7 +316,7 @@ private int uninterruptiblePushJNIRef(Address ref, boolean isRef) {
// we count all slots so that releasing them is straight forward
JNIRefsTop += BYTES_IN_ADDRESS;
// ensure null is always seen as slot zero
JNIRefs.set(JNIRefsTop >> LOG_BYTES_IN_ADDRESS, Magic.objectAsAddress(ref));
JNIRefs.set(JNIRefsTop >> LOG_BYTES_IN_ADDRESS, ref);
return JNIRefsTop;
}
}
Expand Down Expand Up @@ -417,18 +419,20 @@ public Object exitFromJNI(int offset) {
* @return reference at that offset
*/
public Object getJNIRef(int offset) {
if (offset > JNIRefsTop) {
VM.sysWrite("JNI ERROR: getJNIRef for illegal offset > TOP, ");
VM.sysWrite(offset);
VM.sysWrite("(top is ");
VM.sysWrite(JNIRefsTop);
VM.sysWrite(")\n");
RVMThread.dumpStack();
if (offset == 0) {
return null;
}
if (offset < 0) {
} else if (offset < 0) {
return JNIGlobalRefTable.ref(offset);
} else {
if (VM.VerifyAssertions && offset > JNIRefsTop) {
VM.sysWrite("JNI ERROR: getJNIRef for illegal offset > TOP, ");
VM.sysWrite(offset);
VM.sysWrite("(top is ");
VM.sysWrite(JNIRefsTop);
VM.sysWrite(")\n");
RVMThread.dumpStack();
return null;
}
return Magic.addressAsObject(JNIRefs.get(offset >> LOG_BYTES_IN_ADDRESS));
}
}
Expand Down Expand Up @@ -501,6 +505,7 @@ public Throwable getException() {
*/
public static void initFunctionTable(FunctionTable functions) {
JNIFunctions = functions;
BootRecord.the_boot_record.JNIFunctions = functions;
if (VM.BuildForPowerOpenABI) {
// Allocate the linkage triplets in the bootimage too (so they won't move)
LinkageTriplets = LinkageTripletTable.allocate(functions.length());
Expand Down

0 comments on commit e923bf0

Please sign in to comment.