Java Code Examples for jdk.internal.dynalink.linker.LinkRequest#getCallSiteDescriptor()
The following examples show how to use
jdk.internal.dynalink.linker.LinkRequest#getCallSiteDescriptor() .
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: BrowserJSObjectLinker.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception { final LinkRequest requestWithoutContext = request.withoutRuntimeContext(); // Nashorn has no runtime context final Object self = requestWithoutContext.getReceiver(); final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor(); checkJSObjectClass(); if (desc.getNameTokenCount() < 2 || !"dyn".equals(desc.getNameToken(CallSiteDescriptor.SCHEME))) { // We only support standard "dyn:*[:*]" operations return null; } GuardedInvocation inv; if (jsObjectClass.isInstance(self)) { inv = lookup(desc, request, linkerServices); inv = inv.replaceMethods(linkerServices.filterInternalObjects(inv.getInvocation()), inv.getGuard()); } else { throw new AssertionError(); // Should never reach here. } return Bootstrap.asTypeSafeReturn(inv, linkerServices, desc); }
Example 2
Source File: BrowserJSObjectLinker.java From jdk8u_nashorn with GNU General Public License v2.0 | 6 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception { final LinkRequest requestWithoutContext = request.withoutRuntimeContext(); // Nashorn has no runtime context final Object self = requestWithoutContext.getReceiver(); final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor(); checkJSObjectClass(); if (desc.getNameTokenCount() < 2 || !"dyn".equals(desc.getNameToken(CallSiteDescriptor.SCHEME))) { // We only support standard "dyn:*[:*]" operations return null; } GuardedInvocation inv; if (jsObjectClass.isInstance(self)) { inv = lookup(desc, request, linkerServices); inv = inv.replaceMethods(linkerServices.filterInternalObjects(inv.getInvocation()), inv.getGuard()); } else { throw new AssertionError(); // Should never reach here. } return Bootstrap.asTypeSafeReturn(inv, linkerServices, desc); }
Example 3
Source File: ReflectionCheckLinker.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private static void checkLinkRequest(final LinkRequest origRequest) { final SecurityManager sm = System.getSecurityManager(); if (sm != null) { final LinkRequest requestWithoutContext = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context final Object self = requestWithoutContext.getReceiver(); // allow 'static' access on Class objects representing public classes of non-restricted packages if ((self instanceof Class) && Modifier.isPublic(((Class<?>)self).getModifiers())) { final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor(); if(CallSiteDescriptorFactory.tokenizeOperators(desc).contains("getProp")) { if ("static".equals(desc.getNameToken(CallSiteDescriptor.NAME_OPERAND))) { if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) { // If "getProp:static" passes access checks, allow access. return; } } } } checkReflectionPermission(sm); } }
Example 4
Source File: NashornBottomLinker.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private static GuardedInvocation linkNull(final LinkRequest linkRequest) { final NashornCallSiteDescriptor desc = (NashornCallSiteDescriptor)linkRequest.getCallSiteDescriptor(); final String operator = desc.getFirstOperator(); switch (operator) { case "new": case "call": throw typeError("not.a.function", "null"); case "callMethod": case "getMethod": throw typeError("no.such.function", getArgument(linkRequest), "null"); case "getProp": case "getElem": throw typeError("cant.get.property", getArgument(linkRequest), "null"); case "setProp": case "setElem": throw typeError("cant.set.property", getArgument(linkRequest), "null"); default: break; } throw new AssertionError("unknown call type " + desc); }
Example 5
Source File: StaticClassLinker.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception { final GuardedInvocation gi = super.getGuardedInvocation(request, linkerServices); if(gi != null) { return gi; } final CallSiteDescriptor desc = request.getCallSiteDescriptor(); final String op = desc.getNameToken(CallSiteDescriptor.OPERATOR); if("new" == op && constructor != null) { final MethodHandle ctorInvocation = constructor.getInvocation(desc, linkerServices); if(ctorInvocation != null) { return new GuardedInvocation(ctorInvocation, getClassGuard(desc.getMethodType())); } } return null; }
Example 6
Source File: BeansLinker.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception { final CallSiteDescriptor callSiteDescriptor = request.getCallSiteDescriptor(); final int l = callSiteDescriptor.getNameTokenCount(); // All names conforming to the dynalang MOP should have at least two tokens, the first one being "dyn" if(l < 2 || "dyn" != callSiteDescriptor.getNameToken(CallSiteDescriptor.SCHEME)) { return null; } final Object receiver = request.getReceiver(); if(receiver == null) { // Can't operate on null return null; } return getLinkerForClass(receiver.getClass()).getGuardedInvocation(request, linkerServices); }
Example 7
Source File: StaticClassLinker.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override public GuardedInvocation getGuardedInvocation(LinkRequest request, LinkerServices linkerServices) throws Exception { final GuardedInvocation gi = super.getGuardedInvocation(request, linkerServices); if(gi != null) { return gi; } final CallSiteDescriptor desc = request.getCallSiteDescriptor(); final String op = desc.getNameToken(CallSiteDescriptor.OPERATOR); if("new" == op && constructor != null) { final MethodHandle ctorInvocation = constructor.getInvocation(desc, linkerServices); if(ctorInvocation != null) { return new GuardedInvocation(ctorInvocation, getClassGuard(desc.getMethodType())); } } return null; }
Example 8
Source File: StaticClassLinker.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception { final GuardedInvocation gi = super.getGuardedInvocation(request, linkerServices); if(gi != null) { return gi; } final CallSiteDescriptor desc = request.getCallSiteDescriptor(); final String op = desc.getNameToken(CallSiteDescriptor.OPERATOR); if("new" == op && constructor != null) { final MethodHandle ctorInvocation = constructor.getInvocation(desc, linkerServices); if(ctorInvocation != null) { return new GuardedInvocation(ctorInvocation, getClassGuard(desc.getMethodType())); } } return null; }
Example 9
Source File: NashornBottomLinker.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static GuardedInvocation linkNull(final LinkRequest linkRequest) { final NashornCallSiteDescriptor desc = (NashornCallSiteDescriptor)linkRequest.getCallSiteDescriptor(); final String operator = desc.getFirstOperator(); switch (operator) { case "new": case "call": throw typeError("not.a.function", "null"); case "callMethod": case "getMethod": throw typeError("no.such.function", getArgument(linkRequest), "null"); case "getProp": case "getElem": throw typeError("cant.get.property", getArgument(linkRequest), "null"); case "setProp": case "setElem": throw typeError("cant.set.property", getArgument(linkRequest), "null"); default: break; } throw new AssertionError("unknown call type " + desc); }
Example 10
Source File: BrowserJSObjectLinker.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception { final LinkRequest requestWithoutContext = request.withoutRuntimeContext(); // Nashorn has no runtime context final Object self = requestWithoutContext.getReceiver(); final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor(); checkJSObjectClass(); if (desc.getNameTokenCount() < 2 || !"dyn".equals(desc.getNameToken(CallSiteDescriptor.SCHEME))) { // We only support standard "dyn:*[:*]" operations return null; } GuardedInvocation inv; if (jsObjectClass.isInstance(self)) { inv = lookup(desc, request, linkerServices); inv = inv.replaceMethods(linkerServices.filterInternalObjects(inv.getInvocation()), inv.getGuard()); } else { throw new AssertionError(); // Should never reach here. } return Bootstrap.asTypeSafeReturn(inv, linkerServices, desc); }
Example 11
Source File: BeansLinker.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception { final CallSiteDescriptor callSiteDescriptor = request.getCallSiteDescriptor(); final int l = callSiteDescriptor.getNameTokenCount(); // All names conforming to the dynalang MOP should have at least two tokens, the first one being "dyn" if(l < 2 || "dyn" != callSiteDescriptor.getNameToken(CallSiteDescriptor.SCHEME)) { return null; } final Object receiver = request.getReceiver(); if(receiver == null) { // Can't operate on null return null; } return getLinkerForClass(receiver.getClass()).getGuardedInvocation(request, linkerServices); }
Example 12
Source File: NashornBeansLinker.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception { final Object self = linkRequest.getReceiver(); final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor(); if (self instanceof ConsString) { // In order to treat ConsString like a java.lang.String we need a link request with a string receiver. final Object[] arguments = linkRequest.getArguments(); arguments[0] = ""; final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(desc, arguments); final GuardedInvocation invocation = getGuardedInvocation(beansLinker, forgedLinkRequest, linkerServices); // If an invocation is found we add a filter that makes it work for both Strings and ConsStrings. return invocation == null ? null : invocation.filterArguments(0, FILTER_CONSSTRING); } if (self != null && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) { // Support dyn:call on any object that supports some @FunctionalInterface // annotated interface. This way Java method, constructor references or // implementations of java.util.function.* interfaces can be called as though // those are script functions. final Method m = getFunctionalInterfaceMethod(self.getClass()); if (m != null) { final MethodType callType = desc.getMethodType(); // 'callee' and 'thiz' passed from script + actual arguments if (callType.parameterCount() != m.getParameterCount() + 2) { throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self)); } return new GuardedInvocation( // drop 'thiz' passed from the script. MH.dropArguments(linkerServices.filterInternalObjects(desc.getLookup().unreflect(m)), 1, callType.parameterType(1)), Guards.getInstanceOfGuard( m.getDeclaringClass())).asTypeSafeReturn( new NashornBeansLinkerServices(linkerServices), callType); } } return getGuardedInvocation(beansLinker, linkRequest, linkerServices); }
Example 13
Source File: NashornLinker.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception { final LinkRequest requestWithoutContext = request.withoutRuntimeContext(); // Nashorn has no runtime context final Object self = requestWithoutContext.getReceiver(); final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor(); if (desc.getNameTokenCount() < 2 || !"dyn".equals(desc.getNameToken(CallSiteDescriptor.SCHEME))) { // We only support standard "dyn:*[:*]" operations return null; } return Bootstrap.asTypeSafeReturn(getGuardedInvocation(self, request, desc), linkerServices, desc); }
Example 14
Source File: NashornBottomLinker.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static String getArgument(final LinkRequest linkRequest) { final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor(); if (desc.getNameTokenCount() > 2) { return desc.getNameToken(2); } return ScriptRuntime.safeToString(linkRequest.getArguments()[1]); }
Example 15
Source File: NashornBeansLinker.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception { final Object self = linkRequest.getReceiver(); final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor(); if (self instanceof ConsString) { // In order to treat ConsString like a java.lang.String we need a link request with a string receiver. final Object[] arguments = linkRequest.getArguments(); arguments[0] = ""; final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(desc, arguments); final GuardedInvocation invocation = getGuardedInvocation(beansLinker, forgedLinkRequest, linkerServices); // If an invocation is found we add a filter that makes it work for both Strings and ConsStrings. return invocation == null ? null : invocation.filterArguments(0, FILTER_CONSSTRING); } if (self != null && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) { // Support dyn:call on any object that supports some @FunctionalInterface // annotated interface. This way Java method, constructor references or // implementations of java.util.function.* interfaces can be called as though // those are script functions. final String name = getFunctionalInterfaceMethodName(self.getClass()); if (name != null) { final MethodType callType = desc.getMethodType(); // drop callee (Undefined ScriptFunction) and change the request to be dyn:callMethod:<name> final NashornCallSiteDescriptor newDesc = NashornCallSiteDescriptor.get(desc.getLookup(), "dyn:callMethod:" + name, desc.getMethodType().dropParameterTypes(1, 2), NashornCallSiteDescriptor.getFlags(desc)); final GuardedInvocation gi = getGuardedInvocation(beansLinker, linkRequest.replaceArguments(newDesc, linkRequest.getArguments()), new NashornBeansLinkerServices(linkerServices)); // drop 'thiz' passed from the script. return gi.replaceMethods( MH.dropArguments(linkerServices.filterInternalObjects(gi.getInvocation()), 1, callType.parameterType(1)), gi.getGuard()); } } return getGuardedInvocation(beansLinker, linkRequest, linkerServices); }
Example 16
Source File: NashornBottomLinker.java From hottub with GNU General Public License v2.0 | 5 votes |
private static String getArgument(final LinkRequest linkRequest) { final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor(); if (desc.getNameTokenCount() > 2) { return desc.getNameToken(2); } return ScriptRuntime.safeToString(linkRequest.getArguments()[1]); }
Example 17
Source File: ReflectionCheckLinker.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
private static void checkLinkRequest(final LinkRequest origRequest) { final Global global = Context.getGlobal(); final ClassFilter cf = global.getClassFilter(); if (cf != null) { throw typeError("no.reflection.with.classfilter"); } final SecurityManager sm = System.getSecurityManager(); if (sm != null) { final LinkRequest requestWithoutContext = origRequest.withoutRuntimeContext(); // Nashorn has no runtime context final Object self = requestWithoutContext.getReceiver(); // allow 'static' access on Class objects representing public classes of non-restricted packages if ((self instanceof Class) && Modifier.isPublic(((Class<?>)self).getModifiers())) { final CallSiteDescriptor desc = requestWithoutContext.getCallSiteDescriptor(); if(CallSiteDescriptorFactory.tokenizeOperators(desc).contains("getProp")) { if (desc.getNameTokenCount() > CallSiteDescriptor.NAME_OPERAND && "static".equals(desc.getNameToken(CallSiteDescriptor.NAME_OPERAND))) { if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) { // If "getProp:static" passes access checks, allow access. return; } } } } checkReflectionPermission(sm); } }
Example 18
Source File: NashornBeansLinker.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Override public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception { final Object self = linkRequest.getReceiver(); final CallSiteDescriptor desc = linkRequest.getCallSiteDescriptor(); if (self instanceof ConsString) { // In order to treat ConsString like a java.lang.String we need a link request with a string receiver. final Object[] arguments = linkRequest.getArguments(); arguments[0] = ""; final LinkRequest forgedLinkRequest = linkRequest.replaceArguments(desc, arguments); final GuardedInvocation invocation = getGuardedInvocation(beansLinker, forgedLinkRequest, linkerServices); // If an invocation is found we add a filter that makes it work for both Strings and ConsStrings. return invocation == null ? null : invocation.filterArguments(0, FILTER_CONSSTRING); } if (self != null && "call".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) { // Support dyn:call on any object that supports some @FunctionalInterface // annotated interface. This way Java method, constructor references or // implementations of java.util.function.* interfaces can be called as though // those are script functions. final String name = getFunctionalInterfaceMethodName(self.getClass()); if (name != null) { final MethodType callType = desc.getMethodType(); // drop callee (Undefined ScriptFunction) and change the request to be dyn:callMethod:<name> final NashornCallSiteDescriptor newDesc = NashornCallSiteDescriptor.get(desc.getLookup(), "dyn:callMethod:" + name, desc.getMethodType().dropParameterTypes(1, 2), NashornCallSiteDescriptor.getFlags(desc)); final GuardedInvocation gi = getGuardedInvocation(beansLinker, linkRequest.replaceArguments(newDesc, linkRequest.getArguments()), new NashornBeansLinkerServices(linkerServices)); // drop 'thiz' passed from the script. return gi.replaceMethods( MH.dropArguments(linkerServices.filterInternalObjects(gi.getInvocation()), 1, callType.parameterType(1)), gi.getGuard()); } } return getGuardedInvocation(beansLinker, linkRequest, linkerServices); }
Example 19
Source File: NashornStaticClassLinker.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest, LinkerServices linkerServices) throws Exception { final LinkRequest request = linkRequest.withoutRuntimeContext(); // Nashorn has no runtime context final Object self = request.getReceiver(); if (self.getClass() != StaticClass.class) { return null; } final Class<?> receiverClass = ((StaticClass) self).getRepresentedClass(); Bootstrap.checkReflectionAccess(receiverClass, true); final CallSiteDescriptor desc = request.getCallSiteDescriptor(); // We intercept "new" on StaticClass instances to provide additional capabilities if ("new".equals(desc.getNameToken(CallSiteDescriptor.OPERATOR))) { // make sure new is on accessible Class Context.checkPackageAccess(receiverClass); // Is the class abstract? (This includes interfaces.) if (NashornLinker.isAbstractClass(receiverClass)) { // Change this link request into a link request on the adapter class. final Object[] args = request.getArguments(); args[0] = JavaAdapterFactory.getAdapterClassFor(new Class<?>[] { receiverClass }, null, linkRequest.getCallSiteDescriptor().getLookup()); final LinkRequest adapterRequest = request.replaceArguments(request.getCallSiteDescriptor(), args); final GuardedInvocation gi = checkNullConstructor(delegate(linkerServices, adapterRequest), receiverClass); // Finally, modify the guard to test for the original abstract class. return gi.replaceMethods(gi.getInvocation(), Guards.getIdentityGuard(self)); } // If the class was not abstract, just delegate linking to the standard StaticClass linker. Make an // additional check to ensure we have a constructor. We could just fall through to the next "return" // statement, except we also insert a call to checkNullConstructor() which throws an ECMAScript TypeError // with a more intuitive message when no suitable constructor is found. return checkNullConstructor(delegate(linkerServices, request), receiverClass); } // In case this was not a "new" operation, just delegate to the the standard StaticClass linker. return delegate(linkerServices, request); }
Example 20
Source File: NashornBottomLinker.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
private static GuardedInvocation linkBean(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception { final NashornCallSiteDescriptor desc = (NashornCallSiteDescriptor)linkRequest.getCallSiteDescriptor(); final Object self = linkRequest.getReceiver(); final String operator = desc.getFirstOperator(); switch (operator) { case "new": if(BeansLinker.isDynamicConstructor(self)) { throw typeError("no.constructor.matches.args", ScriptRuntime.safeToString(self)); } if(BeansLinker.isDynamicMethod(self)) { throw typeError("method.not.constructor", ScriptRuntime.safeToString(self)); } throw typeError("not.a.function", desc.getFunctionErrorMessage(self)); case "call": if(BeansLinker.isDynamicConstructor(self)) { throw typeError("constructor.requires.new", ScriptRuntime.safeToString(self)); } if(BeansLinker.isDynamicMethod(self)) { throw typeError("no.method.matches.args", ScriptRuntime.safeToString(self)); } throw typeError("not.a.function", desc.getFunctionErrorMessage(self)); case "callMethod": throw typeError("no.such.function", getArgument(linkRequest), ScriptRuntime.safeToString(self)); case "getMethod": // evaluate to undefined, later on Undefined will take care of throwing TypeError return getInvocation(MH.dropArguments(GET_UNDEFINED.get(TYPE_OBJECT_INDEX), 0, Object.class), self, linkerServices, desc); case "getProp": case "getElem": if(NashornCallSiteDescriptor.isOptimistic(desc)) { throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT); } if (desc.getOperand() != null) { return getInvocation(EMPTY_PROP_GETTER, self, linkerServices, desc); } return getInvocation(EMPTY_ELEM_GETTER, self, linkerServices, desc); case "setProp": case "setElem": { final boolean strict = NashornCallSiteDescriptor.isStrict(desc); if (strict) { throw typeError("cant.set.property", getArgument(linkRequest), ScriptRuntime.safeToString(self)); } if (desc.getOperand() != null) { return getInvocation(EMPTY_PROP_SETTER, self, linkerServices, desc); } return getInvocation(EMPTY_ELEM_SETTER, self, linkerServices, desc); } default: break; } throw new AssertionError("unknown call type " + desc); }