Skip to content
Snippets Groups Projects
Commit ee0c9b86 authored by Florian Angerer's avatar Florian Angerer
Browse files

Initialize retrieve callbacks address on first use.

parent ed5129f9
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,8 @@ import java.util.ArrayList; ...@@ -31,6 +31,8 @@ import java.util.ArrayList;
import java.util.EnumMap; import java.util.EnumMap;
import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.interop.ForeignAccess; import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.InteropException; import com.oracle.truffle.api.interop.InteropException;
import com.oracle.truffle.api.interop.Message; import com.oracle.truffle.api.interop.Message;
...@@ -169,7 +171,7 @@ final class TruffleNFI_Context extends RFFIContext { ...@@ -169,7 +171,7 @@ final class TruffleNFI_Context extends RFFIContext {
} }
} }
private void initCallbacks(RContext context) { private void initCallbacksAddress() {
// get the address of the native thread local // get the address of the native thread local
try { try {
Node bind = Message.createInvoke(1).createNode(); Node bind = Message.createInvoke(1).createNode();
...@@ -179,7 +181,9 @@ final class TruffleNFI_Context extends RFFIContext { ...@@ -179,7 +181,9 @@ final class TruffleNFI_Context extends RFFIContext {
} catch (InteropException ex) { } catch (InteropException ex) {
throw RInternalError.shouldNotReachHere(ex); throw RInternalError.shouldNotReachHere(ex);
} }
}
private void initCallbacks(RContext context) {
if (context.getKind() == ContextKind.SHARE_NOTHING) { if (context.getKind() == ContextKind.SHARE_NOTHING) {
// create and fill a new callbacks table // create and fill a new callbacks table
callbacks = UnsafeAdapter.UNSAFE.allocateMemory(Callbacks.values().length * Unsafe.ARRAY_LONG_INDEX_SCALE); callbacks = UnsafeAdapter.UNSAFE.allocateMemory(Callbacks.values().length * Unsafe.ARRAY_LONG_INDEX_SCALE);
...@@ -203,10 +207,16 @@ final class TruffleNFI_Context extends RFFIContext { ...@@ -203,10 +207,16 @@ final class TruffleNFI_Context extends RFFIContext {
} }
private long callbacks; private long callbacks;
private long callbacksAddress; @CompilationFinal private long callbacksAddress;
private long pushCallbacks() { private long pushCallbacks() {
if (callbacksAddress == 0) {
CompilerDirectives.transferToInterpreterAndInvalidate();
initCallbacksAddress();
}
long oldCallbacks = UnsafeAdapter.UNSAFE.getLong(callbacksAddress); long oldCallbacks = UnsafeAdapter.UNSAFE.getLong(callbacksAddress);
assert callbacks != 0L;
assert callbacksAddress != 0L;
UnsafeAdapter.UNSAFE.putLong(callbacksAddress, callbacks); UnsafeAdapter.UNSAFE.putLong(callbacksAddress, callbacks);
return oldCallbacks; return oldCallbacks;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment