@TruffleBoundary public Object access(ArgumentsArrayObject argsArr, int index) { try { return argsArr.args[index]; } catch (IndexOutOfBoundsException ioob) { throw UnknownIdentifierException.raise(Integer.toString(index)); } } }
@SuppressWarnings("deprecation") @Override public InlineKind getInlineKind(ResolvedJavaMethod original, boolean duringPartialEvaluation) { TruffleBoundary truffleBoundary = getAnnotation(TruffleBoundary.class, original); if (truffleBoundary != null) { if (duringPartialEvaluation || !truffleBoundary.allowInlining()) { // Since this method is invoked by the bytecode parser plugins, which can be invoked // by the partial evaluator, we want to prevent inlining across the boundary during // partial evaluation, // even if the TruffleBoundary allows inlining after partial evaluation. if (!truffleBoundary.throwsControlFlowException() && truffleBoundary.transferToInterpreterOnException()) { return InlineKind.DO_NOT_INLINE_DEOPTIMIZE_ON_EXCEPTION; } else { return InlineKind.DO_NOT_INLINE_WITH_EXCEPTION; } } } else if (getAnnotation(TruffleCallBoundary.class, original) != null) { return InlineKind.DO_NOT_INLINE_WITH_EXCEPTION; } return InlineKind.INLINE; }
@Override @SuppressWarnings("deprecation") protected void run(StructuredGraph graph) { for (Node n : graph.getNodes()) { if (n instanceof InvokeWithExceptionNode) { InvokeWithExceptionNode invoke = (InvokeWithExceptionNode) n; ExceptionObjectNode exceptionObject = (ExceptionObjectNode) invoke.exceptionEdge(); FixedNode originalNext = exceptionObject.next(); if (!(originalNext instanceof DeoptimizeNode) && invoke.callTarget().targetMethod() != null) { TruffleBoundary truffleBoundary = invoke.callTarget().targetMethod().getAnnotation(TruffleBoundary.class); if (truffleBoundary != null) { if (!truffleBoundary.throwsControlFlowException() && truffleBoundary.transferToInterpreterOnException()) { addDeoptimizeNode(graph, originalNext); } } } } } }
@TruffleBoundary void addNext(UnwindException ex) { // not common - when more instruments throw unwind if (next == null) { next = ex; } else { next.addNext(ex); } }
@TruffleBoundary public Object access(TopScopeObject ts, String name) { return VMAccessor.JAVAINTEROP.asStaticClassObject(ts.context.findClass(name), VMAccessor.engine().getCurrentHostContext()); } }
@CompilerDirectives.TruffleBoundary private static TruffleObject asTruffleObjectProxy(Object obj, Object languageContext) { if (Proxy.isProxyClass(obj.getClass())) { InvocationHandler h = Proxy.getInvocationHandler(obj); if (h instanceof FunctionProxyHandler) { return ((FunctionProxyHandler) h).functionObj; } else if (h instanceof ObjectProxyHandler) { return ((ObjectProxyHandler) h).obj; } } return JavaObject.forObject(obj, languageContext); }
@TruffleBoundary public Object access(VariableNamesObject varNames, int index) { try { return varNames.names.get(index); } catch (IndexOutOfBoundsException ioob) { throw UnknownIdentifierException.raise(Integer.toString(index)); } } }
@TruffleBoundary public Object access(VariablesMapObject varMap) { return new VariableNamesObject(varMap.slots.keySet()); } }
@Override @TruffleBoundary public boolean isFloat(FrameSlot slot) { return delegate.isFloat(slot); }
@Override @TruffleBoundary public void setDouble(FrameSlot slot, double value) { throw newReadonlyAssertionError(); }
@Override @TruffleBoundary public void setInt(FrameSlot slot, int value) { throw newReadonlyAssertionError(); }
@Override @TruffleBoundary public boolean getBoolean(FrameSlot slot) throws FrameSlotTypeException { return delegate.getBoolean(slot); }
@Override @TruffleBoundary public byte getByte(FrameSlot slot) throws FrameSlotTypeException { return delegate.getByte(slot); }
@Override @TruffleBoundary public FrameDescriptor getFrameDescriptor() { return delegate.getFrameDescriptor(); }
@TruffleBoundary static boolean removeArrayElement(ProxyArray object, Number index) { boolean result; try { result = object.remove(index.longValue()); } catch (ArrayIndexOutOfBoundsException e) { throw UnknownIdentifierException.raise(e.getMessage()); } catch (UnsupportedOperationException e) { throw UnsupportedMessageException.raise(Message.READ); } return result; }
@TruffleBoundary private void doReturn() { SteppingStrategy steppingStrategy = strategyMap.get(Thread.currentThread()); if (steppingStrategy != null) { steppingStrategy.notifyCallExit(); } }
@TruffleBoundary void setThreadSuspendEnabled(boolean enabled) { if (!enabled) { // temporarily disable suspensions in the given thread threadSuspensions.set(ThreadSuspension.DISABLED); } else { threadSuspensions.remove(); } }
@TruffleBoundary @Specialization(guards = {"isList(receiver)"}) protected Object doListIntIndex(JavaObject receiver, int index) { try { return JavaInterop.toGuestValue(((List<?>) receiver.obj).get(index), receiver.languageContext); } catch (IndexOutOfBoundsException e) { CompilerDirectives.transferToInterpreter(); throw UnknownIdentifierException.raise(String.valueOf(index)); } }
@TruffleBoundary static RuntimeException invalidListValue(Object context, Object receiver, Type componentType, int identifier, Object value) { throw newClassCastException( String.format("Invalid value %s for List<%s> %s and index %s.", getValueInfo(context, value), formatComponentType(componentType), getValueInfo(context, receiver), identifier)); }
@TruffleBoundary static RuntimeException nullCoercion(Object languageContext, TruffleObject nullValue, Type targetType) { return newNullPointerException(String.format("Cannot convert null value %s to Java type '%s'.", getValueInfo(languageContext, nullValue), targetType.getTypeName())); }