com.oracle.truffle.api.CompilerDirectives Java Examples
The following examples show how to use
com.oracle.truffle.api.CompilerDirectives.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractSqueakObject.java From trufflesqueak with MIT License | 6 votes |
@Specialization(rewriteOn = RespecializeException.class) protected static final Object invokeMember(final AbstractSqueakObject receiver, final String member, final Object[] arguments, @Shared("lookupNode") @Cached final LookupMethodByStringNode lookupNode, @Shared("classNode") @Cached final SqueakObjectClassNode classNode, @Exclusive @Cached final WrapToSqueakNode wrapNode, @Exclusive @Cached final DispatchUneagerlyNode dispatchNode) throws ArityException { final int actualArity = arguments.length; final Object methodObject = lookupNode.executeLookup(classNode.executeLookup(receiver), toSelector(member, actualArity)); if (methodObject == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); /* DoesNotUnderstand, rewrite this specialization. */ throw new RespecializeException(); } final CompiledMethodObject method = (CompiledMethodObject) methodObject; final int expectedArity = method.getNumArgs(); if (actualArity == expectedArity) { return dispatchNode.executeDispatch(method, ArrayUtils.copyWithFirst(wrapNode.executeObjects(arguments), receiver), NilObject.SINGLETON); } else { throw ArityException.create(1 + expectedArity, 1 + actualArity); } }
Example #2
Source File: ControlPrimitives.java From trufflesqueak with MIT License | 6 votes |
@Specialization(guards = {"receiver != getActiveProcessNode.execute()"}, limit = "1") protected static final PointersObject doSuspendOtherProcess(final PointersObject receiver, @SuppressWarnings("unused") @Shared("getActiveProcessNode") @Cached final GetActiveProcessNode getActiveProcessNode, @Cached final RemoveProcessFromListNode removeProcessNode, @Cached final AbstractPointersObjectReadNode readNode, @Cached final AbstractPointersObjectWriteNode writeNode) { if (readNode.execute(receiver, PROCESS.LIST) == NilObject.SINGLETON) { CompilerDirectives.transferToInterpreter(); throw PrimitiveFailed.BAD_RECEIVER; } else { final PointersObject oldList = readNode.executePointers(receiver, PROCESS.LIST); removeProcessNode.executeRemove(receiver, oldList); writeNode.execute(receiver, PROCESS.LIST, NilObject.SINGLETON); return oldList; } }
Example #3
Source File: HashemEvalRootNode.java From mr-hashemi with Universal Permissive License v1.0 | 6 votes |
@Override public Object execute(VirtualFrame frame) { /* Lazy registrations of functions on first execution. */ if (!registered) { /* Function registration is a slow-path operation that must not be compiled. */ CompilerDirectives.transferToInterpreterAndInvalidate(); lookupContextReference(HashemLanguage.class).get().getFunctionRegistry().register(functions); registered = true; } if (mainCallNode == null) { /* The source code did not have a "main" function, so nothing to execute. */ return HashemPooch.SINGLETON; } else { /* Conversion of arguments to types understood by SL. */ Object[] arguments = frame.getArguments(); for (int i = 0; i < arguments.length; i++) { arguments[i] = HashemContext.fromForeignValue(arguments[i]); } return mainCallNode.call(arguments); } }
Example #4
Source File: SqueakImageContext.java From trufflesqueak with MIT License | 6 votes |
public NativeObject getResourcesDirectory() { if (resourcesPathBytes == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); final String languageHome = getLanguage().getTruffleLanguageHome(); final TruffleFile path; if (languageHome != null) { path = getHomePath().resolve("resources"); } else { /* Fallback to image directory. */ path = env.getInternalTruffleFile(getImagePath()).getParent(); if (path == null) { throw SqueakException.create("`parent` should not be `null`."); } } resourcesPathBytes = MiscUtils.stringToBytes(path.getAbsoluteFile().getPath()); } return NativeObject.newNativeBytes(this, byteStringClass, resourcesPathBytes.clone()); }
Example #5
Source File: DeviceArray.java From grcuda with BSD 3-Clause "New" or "Revised" License | 6 votes |
@ExportMessage Object readMember(String memberName, @Shared("memberName") @Cached("createIdentityProfile()") ValueProfile memberProfile) throws UnknownIdentifierException { if (!isMemberReadable(memberName, memberProfile)) { CompilerDirectives.transferToInterpreter(); throw UnknownIdentifierException.create(memberName); } if (POINTER.equals(memberName)) { return getPointer(); } if (COPY_FROM.equals(memberName)) { return new DeviceArrayCopyFunction(this, DeviceArrayCopyFunction.CopyDirection.FROM_POINTER); } if (COPY_TO.equals(memberName)) { return new DeviceArrayCopyFunction(this, DeviceArrayCopyFunction.CopyDirection.TO_POINTER); } if (FREE.equals(memberName)) { return new DeviceArrayFreeFunction(); } if (IS_MEMORY_FREED.equals(memberName)) { return isMemoryFreed(); } CompilerDirectives.transferToInterpreter(); throw UnknownIdentifierException.create(memberName); }
Example #6
Source File: ArrayNode.java From grcuda with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Specialization Object doDefault(VirtualFrame frame, @CachedContext(GrCUDALanguage.class) GrCUDAContext context) { final CUDARuntime runtime = context.getCUDARuntime(); long[] elementsPerDim = new long[sizeNodes.length]; int dim = 0; for (ExpressionNode sizeNode : sizeNodes) { Object size = sizeNode.execute(frame); if (!(size instanceof Number)) { CompilerDirectives.transferToInterpreter(); throw new GrCUDAInternalException("size in dimension " + dim + " must be a number", this); } elementsPerDim[dim] = ((Number) size).longValue(); dim += 1; } if (sizeNodes.length == 1) { return new DeviceArray(runtime, elementsPerDim[0], elementType); } else { final boolean columnMajorOrder = false; return new MultiDimDeviceArray(runtime, elementType, elementsPerDim, columnMajorOrder); } }
Example #7
Source File: CallNode.java From grcuda with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Specialization Object doDefault(VirtualFrame frame, @CachedLibrary(limit = "2") InteropLibrary interop, @CachedContext(GrCUDALanguage.class) GrCUDAContext context) { String[] functionName = identifier.getIdentifierName(); Namespace namespace = context.getRootNamespace(); Optional<Object> maybeFunction = namespace.lookup(functionName); if (!maybeFunction.isPresent() || !(maybeFunction.get() instanceof Function)) { CompilerDirectives.transferToInterpreter(); throw new GrCUDAException("function '" + GrCUDAException.format(functionName) + "' not found", this); } Function function = (Function) maybeFunction.get(); Object[] argumentValues = new Object[argumentNodes.length]; for (int i = 0; i < argumentNodes.length; i++) { argumentValues[i] = argumentNodes[i].execute(frame); } try { return interop.execute(function, argumentValues); } catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); throw new GrCUDAException(e.getMessage(), this); } }
Example #8
Source File: FrameAccess.java From trufflesqueak with MIT License | 6 votes |
@TruffleBoundary public static MaterializedFrame findFrameForMarker(final FrameMarker frameMarker) { CompilerDirectives.bailout("Finding materializable frames should never be part of compiled code as it triggers deopts"); LogUtils.ITERATE_FRAMES.fine("Iterating frames to find a marker..."); final Frame frame = Truffle.getRuntime().iterateFrames(frameInstance -> { final Frame current = frameInstance.getFrame(FrameInstance.FrameAccess.READ_ONLY); if (!isTruffleSqueakFrame(current)) { return null; } LogUtils.ITERATE_FRAMES.fine(() -> "..." + FrameAccess.getMethod(current).toString()); if (frameMarker == getMarker(current)) { return frameInstance.getFrame(FrameInstance.FrameAccess.MATERIALIZE); } return null; }); if (frame == null) { throw SqueakException.create("Could not find frame for:", frameMarker); } else { return frame.materialize(); } }
Example #9
Source File: UnwindContextChainNode.java From trufflesqueak with MIT License | 6 votes |
@Specialization(guards = {"startContext != targetContext"}) protected static final ContextObject doUnwind(final ContextObject startContext, final ContextObject targetContext, final Object returnValue, @CachedContext(SqueakLanguage.class) final SqueakImageContext image) { ContextObject context = startContext; while (context != targetContext) { final AbstractSqueakObject sender = context.getSender(); if (sender == NilObject.SINGLETON) { CompilerDirectives.transferToInterpreter(); image.printToStdErr("Unwind error: sender of", context, "is nil, unwinding towards", targetContext, "with return value:", returnValue); break; } context.terminate(); context = (ContextObject) sender; } targetContext.push(returnValue); return targetContext; }
Example #10
Source File: Kernel.java From grcuda with BSD 3-Clause "New" or "Revised" License | 6 votes |
@ExportMessage Object execute(Object[] arguments, @CachedLibrary(limit = "3") InteropLibrary gridSizeAccess, @CachedLibrary(limit = "3") InteropLibrary gridSizeElementAccess, @CachedLibrary(limit = "3") InteropLibrary blockSizeAccess, @CachedLibrary(limit = "3") InteropLibrary blockSizeElementAccess, @CachedLibrary(limit = "3") InteropLibrary sharedMemoryAccess) throws UnsupportedTypeException, ArityException { int dynamicSharedMemoryBytes; if (arguments.length == 2) { dynamicSharedMemoryBytes = 0; } else if (arguments.length == 3) { // dynamic shared memory specified dynamicSharedMemoryBytes = extractNumber(arguments[2], "dynamicSharedMemory", sharedMemoryAccess); } else { CompilerDirectives.transferToInterpreter(); throw ArityException.create(2, arguments.length); } Dim3 gridSize = extractDim3(arguments[0], "gridSize", gridSizeAccess, gridSizeElementAccess); Dim3 blockSize = extractDim3(arguments[1], "blockSize", blockSizeAccess, blockSizeElementAccess); KernelConfig config = new KernelConfig(gridSize, blockSize, dynamicSharedMemoryBytes); return new ConfiguredKernel(this, config); }
Example #11
Source File: Device.java From grcuda with BSD 3-Clause "New" or "Revised" License | 6 votes |
@ExportMessage Object readMember(String memberName, @Shared("memberName") @Cached("createIdentityProfile()") ValueProfile memberProfile) throws UnknownIdentifierException { if (!isMemberReadable(memberName, memberProfile)) { CompilerDirectives.transferToInterpreter(); throw UnknownIdentifierException.create(memberName); } if (ID.equals(memberName)) { return deviceId; } if (PROPERTIES.equals(memberName)) { return properties; } if (IS_CURRENT.equals(memberName)) { return new IsCurrentFunction(deviceId, runtime); } if (SET_CURRENT.equals(memberName)) { return new SetCurrentFunction(deviceId, runtime); } CompilerDirectives.transferToInterpreter(); throw UnknownIdentifierException.create(memberName); }
Example #12
Source File: FrameSlotReadNode.java From trufflesqueak with MIT License | 6 votes |
@Specialization(replaces = {"readBoolean", "readLong", "readDouble"}) protected final Object readAndClearObject(final Frame frame) { final Object value; if (!frame.isObject(getSlot())) { /* * The FrameSlotKind has been set to Object, so from now on all writes to the slot * will be Object writes. However, now we are in a frame that still has an old * non-Object value. This is a slow-path operation: we read the non-Object value, * and clear it immediately as an Object value so that we do not hit this path again * multiple times for the same slot of the same frame. */ CompilerDirectives.transferToInterpreter(); value = frame.getValue(getSlot()); } else { value = FrameUtil.getObjectSafe(frame, getSlot()); } frame.setObject(getSlot(), null); return value; }
Example #13
Source File: DispatchEagerlyNode.java From trufflesqueak with MIT License | 6 votes |
@Specialization(guards = {"cachedMethod.hasPrimitive()", "method == cachedMethod", "primitiveNode != null"}, // limit = "INLINE_CACHE_SIZE", assumptions = {"cachedMethod.getCallTargetStable()"}, rewriteOn = PrimitiveFailed.class) protected static final Object doPrimitiveEagerly(final VirtualFrame frame, @SuppressWarnings("unused") final CompiledMethodObject method, final Object[] receiverAndArguments, @SuppressWarnings("unused") @Cached("method") final CompiledMethodObject cachedMethod, @Cached("forIndex(cachedMethod, false, cachedMethod.primitiveIndex())") final AbstractPrimitiveNode primitiveNode, @Cached final CreateEagerArgumentsNode createEagerArgumentsNode, @Cached final PrimitiveFailedCounter failureCounter) { try { return primitiveNode.executeWithArguments(frame, createEagerArgumentsNode.executeCreate(primitiveNode.getNumArguments(), receiverAndArguments)); } catch (final PrimitiveFailed pf) { CompilerDirectives.transferToInterpreterAndInvalidate(); if (failureCounter.shouldNoLongerSendEagerly()) { throw pf; // Rewrite specialization. } else { // Slow path send to fallback code. return IndirectCallNode.getUncached().call(cachedMethod.getCallTarget(), FrameAccess.newWith(cachedMethod, FrameAccess.getContextOrMarkerSlow(frame), null, receiverAndArguments)); } } }
Example #14
Source File: GetContextOrMarkerNode.java From trufflesqueak with MIT License | 6 votes |
public Object execute(final VirtualFrame frame) { if (contextSlot == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); contextSlot = FrameAccess.getContextSlot(frame); markerSlot = FrameAccess.getMarkerSlot(frame); } final ContextObject context = FrameAccess.getContext(frame, contextSlot); if (hasContextProfile.profile(context != null)) { return context; } else { final FrameMarker marker = FrameAccess.getMarker(frame, markerSlot); if (hasMarkerProfile.profile(marker != null)) { return marker; } else { final FrameMarker newMarker = new FrameMarker(); FrameAccess.setMarker(frame, markerSlot, newMarker); return newMarker; } } }
Example #15
Source File: MappedFunction.java From grcuda with BSD 3-Clause "New" or "Revised" License | 6 votes |
@ExportMessage Object execute(Object[] arguments, @CachedLibrary("this.parent") InteropLibrary parentInterop, @CachedLibrary(limit = "2") InteropLibrary memberInterop) throws ArityException, UnsupportedTypeException, UnsupportedMessageException { if (arguments.length != 3) { CompilerDirectives.transferToInterpreter(); throw ArityException.create(3, arguments.length); } Object value = parentInterop.execute(parent, arguments); try { return memberInterop.readMember(value, name); } catch (UnsupportedMessageException | UnknownIdentifierException e) { CompilerDirectives.transferToInterpreter(); throw new MapException("cannot read member '" + name + "' from argument " + parent); } }
Example #16
Source File: ControlPrimitives.java From trufflesqueak with MIT License | 6 votes |
@Specialization protected final Object doResume(final VirtualFrame frame, final PointersObject receiver, @Cached final AbstractPointersObjectReadNode readNode, @Cached final ResumeProcessNode resumeProcessNode) { if (!(readNode.execute(receiver, PROCESS.SUSPENDED_CONTEXT) instanceof ContextObject)) { CompilerDirectives.transferToInterpreter(); throw PrimitiveFailed.GENERIC_ERROR; } try { resumeProcessNode.executeResume(frame, receiver); } catch (final ProcessSwitch ps) { /* * Leave receiver on stack. It has not been removed from the stack yet, so it is * enough to increment the stack pointer. */ getFrameStackPointerIncrementNode().execute(frame); throw ps; } return receiver; }
Example #17
Source File: GlobalObjectCache.java From nodeprof.js with Apache License 2.0 | 5 votes |
/** * @param someObj a dynamic object which could tell us the jsContext information */ public void addDynamicObject(DynamicObject someObj) { if (jscontext == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); jscontext = JSObject.getJSContext(someObj); if (global == null) { global = jscontext.getRealm().getGlobalObject(); } if (arrayConstructor == null) { arrayConstructor = jscontext.getRealm().getArrayConstructor(); } } }
Example #18
Source File: ControlPrimitives.java From trufflesqueak with MIT License | 5 votes |
private LinkProcessToListNode getLinkProcessToListNode() { if (linkProcessToListNode == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); linkProcessToListNode = insert(LinkProcessToListNode.create()); wakeHighestPriorityNode = insert(WakeHighestPriorityNode.create()); } return linkProcessToListNode; }
Example #19
Source File: ControlPrimitives.java From trufflesqueak with MIT License | 5 votes |
@Specialization(replaces = "performContextCached") protected final Object performContext(final VirtualFrame frame, @SuppressWarnings("unused") final Object receiver, final Object target, final NativeObject selector, final ArrayObject arguments, final ClassObject superClass, @Cached final LookupMethodNode lookupMethodNode, @Cached final DispatchSendSelectorNode dispatchNode) { if (inheritsFromNode.execute(target, superClass)) { final Object lookupResult = lookupMethodNode.executeLookup(superClass, selector); return dispatchNode.executeSend(frame, selector, lookupResult, superClass, getObjectArrayNode.execute(target, arguments)); } else { CompilerDirectives.transferToInterpreter(); throw PrimitiveFailed.BAD_RECEIVER; } }
Example #20
Source File: SqueakProfiles.java From trufflesqueak with MIT License | 5 votes |
@Override @SuppressWarnings("unchecked") public <T> T profile(final T newValue) { // Field needs to be cached in local variable for thread safety and startup speed. final Object cached = cachedValue; if (cached == newValue) { return (T) cached; } else { CompilerDirectives.transferToInterpreterAndInvalidate(); cachedValue = newValue; return newValue; } }
Example #21
Source File: StoragePrimitives.java From trufflesqueak with MIT License | 5 votes |
@Specialization(replaces = "newDirect") protected static final AbstractSqueakObjectWithHash newIndirect(final ClassObject receiver, @Cached final SqueakObjectNewNode newNode, @CachedContext(SqueakLanguage.class) final SqueakImageContext image) { try { return newNode.execute(image, receiver); } catch (final OutOfMemoryError e) { CompilerDirectives.transferToInterpreter(); throw PrimitiveFailed.INSUFFICIENT_OBJECT_MEMORY; } }
Example #22
Source File: Zip.java From trufflesqueak with MIT License | 5 votes |
private boolean determineSizeOfReadStream(final AbstractSqueakObjectWithClassAndHash rcvr) { ClassObject squeakClass = rcvr.getSqueakClass(); while (squeakClass != null && squeakClass.getBasicInstanceSize() >= 13) { squeakClass = squeakClass.getSuperclassOrNull(); } if (squeakClass == null) { return false; } CompilerDirectives.transferToInterpreterAndInvalidate(); readStreamInstSize = squeakClass.getBasicInstanceSize(); return true; }
Example #23
Source File: FrameStackTopNode.java From trufflesqueak with MIT License | 5 votes |
public Object execute(final Frame frame) { if (readNode == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); final int stackPointer = FrameAccess.getStackPointerSlow(frame) - 1; readNode = FrameSlotReadNode.create(FrameAccess.getStackSlot(frame, stackPointer)); } return readNode.executeRead(frame); }
Example #24
Source File: CUDARuntime.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@SuppressWarnings("static-method") private static void checkCUReturnCode(Object result, String... function) { int returnCode; try { returnCode = INTEROP.asInt(result); } catch (UnsupportedMessageException e) { CompilerDirectives.transferToInterpreter(); throw new GrCUDAException( "expected return code as Integer object in " + function + ", got " + result.getClass().getName()); } if (returnCode != 0) { throw new GrCUDAException(returnCode, DriverAPIErrorMessages.getString(returnCode), function); } }
Example #25
Source File: AbstractOSProcessPlugin.java From trufflesqueak with MIT License | 5 votes |
protected final Object getSysCallObject() { assert supportsNFI; if (sysCallObject == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); final Object defaultLibrary = SqueakLanguage.getContext().env.parseInternal(Source.newBuilder("nfi", "default", "native").build()).call(); final InteropLibrary lib = InteropLibrary.getFactory().getUncached(); try { final Object symbol = lib.readMember(defaultLibrary, getFunctionName()); sysCallObject = lib.invokeMember(symbol, "bind", getFunctionSignature()); } catch (UnsupportedMessageException | UnknownIdentifierException | ArityException | UnsupportedTypeException e) { throw PrimitiveFailed.andTransferToInterpreterWithError(e); } } return sysCallObject; }
Example #26
Source File: MapFunction.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static Object bindArgument(Object argument, ArgumentSet argSet, ArgumentSet shreddedArgSet, ArgumentSet valueSet) throws UnsupportedTypeException { try { if (INTEROP.isMemberInvocable(argument, "bind")) { return INTEROP.invokeMember(argument, "bind", argSet, shreddedArgSet, valueSet); } else { Object readMember = INTEROP.readMember(argument, "bind"); return INTEROP.execute(readMember, argSet, shreddedArgSet, valueSet); } } catch (UnsupportedMessageException | UnknownIdentifierException | ArityException e) { CompilerDirectives.transferToInterpreter(); throw new GrCUDAInternalException("unable to bind argument " + argument); } }
Example #27
Source File: ArgumentArray.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@ExportMessage public Object readArrayElement(long index) throws InvalidArrayIndexException { if (!isArrayElementReadable(index)) { CompilerDirectives.transferToInterpreter(); throw InvalidArrayIndexException.create(index); } return values[(int) index]; }
Example #28
Source File: ArgumentArray.java From grcuda with BSD 3-Clause "New" or "Revised" License | 5 votes |
@ExportMessage public void writeArrayElement(long index, Object value) throws InvalidArrayIndexException { if (!isArrayElementReadable(index)) { CompilerDirectives.transferToInterpreter(); throw InvalidArrayIndexException.create(index); } values[(int) index] = value; }
Example #29
Source File: PushBytecodes.java From trufflesqueak with MIT License | 5 votes |
private CompiledBlockObject getBlock(final VirtualFrame frame) { if (cachedBlock == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); cachedBlock = code.findBlock(FrameAccess.getMethod(frame), numArgs, numCopied, getSuccessorIndex(), blockSize); cachedStartPC = cachedBlock.getInitialPC(); } return cachedBlock; }
Example #30
Source File: ArgumentNodes.java From trufflesqueak with MIT License | 5 votes |
@Override public Object execute(final VirtualFrame frame) { if (readNode == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); final CompiledCodeObject blockOrMethod = FrameAccess.getBlockOrMethod(frame); final int stackPointer = FrameAccess.getStackPointer(frame, blockOrMethod); readNode = insert(FrameSlotReadNode.create(blockOrMethod.getStackSlot(stackPointer + argumentIndex))); } return readNode.executeRead(frame); }