8139304: Remove elaborate call site descriptor class hierarchy and factory for them. Remove AutoDiscovery, DefaultPrelinkFilter, and BottomGuardingDynamicLinker as they can be inlined into DynamicLinkerFactory. Remove CallerSensitiveDetector as it can be inlined into AbstractJavaLinker. Make ClassMap non-public
Reviewed-by: hannesw, sundar
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/CallSiteDescriptor.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/CallSiteDescriptor.java
index cf0604d..4606d99 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/CallSiteDescriptor.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/CallSiteDescriptor.java
@@ -83,19 +83,21 @@
package jdk.internal.dynalink;
+import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.StringTokenizer;
+import jdk.internal.dynalink.support.NameCodec;
/**
* An immutable descriptor of a call site. It is an immutable object that contains all the information about a call
- * site: the class performing the lookups, the name of the method being invoked, and the method signature. The library
- * has a default {@link CallSiteDescriptorFactory} for descriptors that you can use, or you can create your own
- * descriptor classes, especially if you need to add further information (values passed in additional parameters to the
- * bootstrap method) to them. Call site descriptors are used in this library in place of passing a real call site to
+ * site: the class performing the lookups, the name of the method being invoked, and the method signature. Call site descriptors are used in this library in place of passing a real call site to
* guarding linkers so they aren't tempted to directly manipulate the call sites. The constructors of built-in
* {@link RelinkableCallSite} implementations all need a call site descriptor. Even if you create your own call site
- * descriptors consider using {@link CallSiteDescriptorFactory#tokenizeName(String)} in your implementation.
+ * descriptors consider using {@link CallSiteDescriptor#tokenizeName(String)} in your implementation.
*/
public interface CallSiteDescriptor {
/**
@@ -155,10 +157,10 @@
public MethodType getMethodType();
/**
- * Returns the lookup passed to the bootstrap method. If the lookup isn't the public lookup, the
- * implementation must check the {@code RuntimePermission("dynalink.getLookup")} permission if a security
- * manager is present.
+ * Returns the lookup passed to the bootstrap method.
* @return the lookup passed to the bootstrap method.
+ * @throws SecurityException if the lookup isn't the {@link MethodHandles#publicLookup()} and a security
+ * manager is present, and a check for {@code RuntimePermission("dynalink.getLookup")} fails.
*/
public Lookup getLookup();
@@ -171,4 +173,43 @@
*/
public CallSiteDescriptor changeMethodType(MethodType newMethodType);
+
+ /**
+ * Tokenizes a composite operation name along pipe characters. I.e. if you have a "dyn:getElem|getProp|getMethod"
+ * operation, returns a list of ["getElem", "getProp", "getMethod"]. The tokens are not interned.
+ * @return a list of tokens
+ */
+ public default List<String> tokenizeOperators() {
+ final String ops = getNameToken(CallSiteDescriptor.OPERATOR);
+ final StringTokenizer tok = new StringTokenizer(ops, CallSiteDescriptor.OPERATOR_DELIMITER);
+ final int count = tok.countTokens();
+ if(count == 1) {
+ return Collections.singletonList(ops);
+ }
+ final String[] tokens = new String[count];
+ for(int i = 0; i < count; ++i) {
+ tokens[i] = tok.nextToken();
+ }
+ return Arrays.asList(tokens);
+ }
+
+ /**
+ * Tokenizes the composite name along colons, as well as {@link NameCodec#decode(String) demangles} and interns
+ * the tokens. The first two tokens are not demangled as they are supposed to be the naming scheme and the name of
+ * the operation which can be expected to consist of just alphabetical characters.
+ * @param name the composite name consisting of colon-separated, possibly mangled tokens.
+ * @return an array of tokens
+ */
+ public static String[] tokenizeName(final String name) {
+ final StringTokenizer tok = new StringTokenizer(name, CallSiteDescriptor.TOKEN_DELIMITER);
+ final String[] tokens = new String[tok.countTokens()];
+ for(int i = 0; i < tokens.length; ++i) {
+ String token = tok.nextToken();
+ if(i > 1) {
+ token = NameCodec.decode(token);
+ }
+ tokens[i] = token.intern();
+ }
+ return tokens;
+ }
}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ChainedCallSite.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ChainedCallSite.java
index 2653e17..ddcde8d 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ChainedCallSite.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ChainedCallSite.java
@@ -175,7 +175,7 @@
// adding any new invocations to it.
if(invocation != null) {
// Remove oldest entry if we're at max length
- if(newInvocations.size() == getMaxChainLength()) {
+ if(newInvocations.size() == checkMaxChainLength(getMaxChainLength())) {
newInvocations.removeFirst();
}
newInvocations.addLast(invocation);
@@ -206,6 +206,13 @@
return target;
}
+ private static int checkMaxChainLength(final int maxChainLength) {
+ if (maxChainLength > 0) {
+ return maxChainLength;
+ }
+ throw new RuntimeException("getMaxChainLength() returned a non-positive value");
+
+ }
/**
* Creates a method that rebuilds our call chain, pruning it of any invalidated switchpoints, and then invokes that
* chain.
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/ClassLoaderGetterContextProvider.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ClassLoaderGetterContextProvider.java
similarity index 95%
rename from nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/ClassLoaderGetterContextProvider.java
rename to nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ClassLoaderGetterContextProvider.java
index f947021..c6bc77b 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/ClassLoaderGetterContextProvider.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ClassLoaderGetterContextProvider.java
@@ -81,7 +81,7 @@
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-package jdk.internal.dynalink.support;
+package jdk.internal.dynalink;
import java.security.AccessControlContext;
import java.security.Permissions;
@@ -92,16 +92,19 @@
* {@code "getClassLoader"} permission that is used by other parts of the code to narrow their set of permissions when
* they're retrieving class loaders in privileged blocks.
*/
-public class ClassLoaderGetterContextProvider {
+final class ClassLoaderGetterContextProvider {
/**
* Canonical instance of {@link AccessControlContext} with a single {@link RuntimePermission} for
* {@code "getClassLoader"} permission.
*/
- public static final AccessControlContext GET_CLASS_LOADER_CONTEXT;
+ static final AccessControlContext GET_CLASS_LOADER_CONTEXT;
static {
final Permissions perms = new Permissions();
perms.add(new RuntimePermission("getClassLoader"));
GET_CLASS_LOADER_CONTEXT = new AccessControlContext(
new ProtectionDomain[] { new ProtectionDomain(null, perms) });
}
+
+ private ClassLoaderGetterContextProvider() {
+ }
}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/ClassMap.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ClassMap.java
similarity index 96%
rename from nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/ClassMap.java
rename to nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ClassMap.java
index 97e37d7..8f11f3a 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/ClassMap.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ClassMap.java
@@ -81,7 +81,7 @@
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-package jdk.internal.dynalink.support;
+package jdk.internal.dynalink;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
@@ -91,6 +91,7 @@
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import jdk.internal.dynalink.support.Guards;
/**
* A dual map that can either strongly or weakly reference a given class depending on whether the class is visible from
@@ -98,7 +99,7 @@
*
* @param <T> the type of the values in the map
*/
-public abstract class ClassMap<T> {
+abstract class ClassMap<T> {
private final ConcurrentMap<Class<?>, T> map = new ConcurrentHashMap<>();
private final Map<Class<?>, Reference<T>> weakMap = new WeakHashMap<>();
private final ClassLoader classLoader;
@@ -109,7 +110,7 @@
*
* @param classLoader the classloader that determines strong referenceability.
*/
- protected ClassMap(final ClassLoader classLoader) {
+ ClassMap(final ClassLoader classLoader) {
this.classLoader = classLoader;
}
@@ -120,7 +121,7 @@
* @param clazz the class to compute the value for
* @return the return value. Must not be null.
*/
- protected abstract T computeValue(Class<?> clazz);
+ abstract T computeValue(Class<?> clazz);
/**
* Returns the value associated with the class
@@ -128,7 +129,7 @@
* @param clazz the class
* @return the value associated with the class
*/
- public T get(final Class<?> clazz) {
+ T get(final Class<?> clazz) {
// Check in fastest first - objects we're allowed to strongly reference
final T v = map.get(clazz);
if(v != null) {
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DefaultBootstrapper.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DefaultBootstrapper.java
deleted file mode 100644
index de609fd..0000000
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DefaultBootstrapper.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * This file is available under and governed by the GNU General Public
- * License version 2 only, as published by the Free Software Foundation.
- * However, the following notice accompanied the original version of this
- * file, and Oracle licenses the original version of this file under the BSD
- * license:
- */
-/*
- Copyright 2009-2013 Attila Szegedi
-
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion.
-
- You may not use this file except in compliance with either the Apache
- License or the BSD License.
-
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you:
-
- You may obtain a copy of the Apache License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied. See the License for the specific language governing
- permissions and limitations under the License.
-
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you:
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the copyright holder nor the names of
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package jdk.internal.dynalink;
-
-import java.lang.invoke.CallSite;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
-
-/**
- * A convenience default bootstrapper that exposes static bootstrap methods which language runtimes that need the very
- * default behavior can use with minimal setup. When first referenced, it will create a dynamic linker with default
- * settings for the {@link DynamicLinkerFactory}, and its bootstrap methods will create {@link MonomorphicCallSite} for
- * all call sites. It has two bootstrap methods: one creates call sites that use the
- * {@link MethodHandles#publicLookup()} as the lookup for all call sites and disregard the one passed in as the caller,
- * and one that just uses the passed caller as the lookup scope. Using the public lookup one is advised if your language
- * runtime has no concept of interacting with Java visibility scopes, as it results in a more lightweight runtime
- * information.
- */
-public class DefaultBootstrapper {
- private static final DynamicLinker dynamicLinker = new DynamicLinkerFactory().createLinker();
-
- private DefaultBootstrapper() {
- }
-
- /**
- * Use this method as your bootstrap method (see the documentation of the java.lang.invoke package for how to do
- * this). In case your language runtime doesn't have a concept of interaction with Java access scopes, you might
- * want to consider using
- * {@link #publicBootstrap(java.lang.invoke.MethodHandles.Lookup, String, MethodType)} instead.
- *
- * @param caller the caller's lookup
- * @param name the name of the method at the call site
- * @param type the method signature at the call site
- * @return a new {@link MonomorphicCallSite} linked with the default dynamic linker.
- */
- public static CallSite bootstrap(final MethodHandles.Lookup caller, final String name, final MethodType type) {
- return bootstrapInternal(caller, name, type);
- }
-
- /**
- * Use this method as your bootstrap method (see the documentation of the java.lang.invoke package for how to do
- * this) when your language runtime doesn't have a concept of interaction with Java access scopes. If you need to
- * preserve the different caller Lookup objects in the call sites, use
- * {@link #bootstrap(java.lang.invoke.MethodHandles.Lookup, String, MethodType)} instead
- *
- * @param caller the caller's lookup. It is ignored as the call sites will be created with
- * {@link MethodHandles#publicLookup()} instead.
- * @param name the name of the method at the call site
- * @param type the method signature at the call site
- * @return a new {@link MonomorphicCallSite} linked with the default dynamic linker.
- */
- public static CallSite publicBootstrap(final MethodHandles.Lookup caller, final String name, final MethodType type) {
- return bootstrapInternal(MethodHandles.publicLookup(), name, type);
- }
-
- private static CallSite bootstrapInternal(final MethodHandles.Lookup caller, final String name, final MethodType type) {
- return dynamicLinker.link(new MonomorphicCallSite(CallSiteDescriptorFactory.create(caller, name, type)));
- }
-}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java
index 0c3f9a2..a167ba0 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java
@@ -93,10 +93,10 @@
import jdk.internal.dynalink.linker.GuardingDynamicLinker;
import jdk.internal.dynalink.linker.LinkRequest;
import jdk.internal.dynalink.linker.LinkerServices;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.internal.dynalink.support.LinkRequestImpl;
import jdk.internal.dynalink.support.Lookup;
import jdk.internal.dynalink.support.RuntimeContextLinkRequestImpl;
+import jdk.internal.dynalink.support.SimpleCallSiteDescriptor;
/**
* The linker for {@link RelinkableCallSite} objects. Users of it (scripting
@@ -130,7 +130,7 @@
* language. If your runtime doesn't have its own language and/or object model
* (i.e., it's a generic scripting shell), you don't need to implement a dynamic
* linker; you would simply not invoke the {@code setPrioritizedLinker} method
- * on the factory, or even better, simply use {@link DefaultBootstrapper}.</li>
+ * on the factory.</li>
*
* <li>The performance of the programs can depend on your choice of the class to
* represent call sites. The above example used {@link MonomorphicCallSite}, but
@@ -141,10 +141,10 @@
* <li>You also need to provide {@link CallSiteDescriptor}s to your call sites.
* They are immutable objects that contain all the information about the call
* site: the class performing the lookups, the name of the method being invoked,
- * and the method signature. The library has a default {@link CallSiteDescriptorFactory}
- * for descriptors that you can use, or you can create your own descriptor
- * classes, especially if you need to add further information (values passed in
- * additional parameters to the bootstrap method) to them.</li>
+ * and the method signature. The library provides a {@link SimpleCallSiteDescriptor},
+ * or you can create your own descriptor classes, especially if you need to add
+ * further information (values passed in additional parameters to the bootstrap method)
+ * to them.</li>
*
* </ul>
*/
@@ -319,6 +319,16 @@
}
/**
+ * Returns the currently processed link request, or null if the method is invoked outside of the linking process.
+ * @return the currently processed link request, or null.
+ * @throws SecurityException if the calling code doesn't have the {@code "dynalink.getCurrentLinkRequest"} runtime
+ * permission.
+ */
+ public static LinkRequest getCurrentLinkRequest() {
+ return LinkerServicesImpl.getCurrentLinkRequest();
+ }
+
+ /**
* Returns {@code true} if the frame represents {@code MethodHandleNatives.linkCallSite()},
* the frame immediately on top of the call site frame when the call site is
* being linked for the first time.
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java
index ec16e98..0265a26 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java
@@ -92,30 +92,27 @@
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.ServiceLoader;
import java.util.Set;
import jdk.internal.dynalink.beans.BeansLinker;
+import jdk.internal.dynalink.linker.GuardedInvocation;
import jdk.internal.dynalink.linker.GuardingDynamicLinker;
import jdk.internal.dynalink.linker.GuardingTypeConverterFactory;
import jdk.internal.dynalink.linker.LinkRequest;
import jdk.internal.dynalink.linker.LinkerServices;
import jdk.internal.dynalink.linker.MethodHandleTransformer;
import jdk.internal.dynalink.linker.MethodTypeConversionStrategy;
-import jdk.internal.dynalink.support.AutoDiscovery;
-import jdk.internal.dynalink.support.BottomGuardingDynamicLinker;
-import jdk.internal.dynalink.support.ClassLoaderGetterContextProvider;
import jdk.internal.dynalink.support.CompositeGuardingDynamicLinker;
import jdk.internal.dynalink.support.CompositeTypeBasedGuardingDynamicLinker;
-import jdk.internal.dynalink.support.DefaultPrelinkFilter;
-import jdk.internal.dynalink.support.LinkerServicesImpl;
-import jdk.internal.dynalink.support.TypeConverterFactory;
import jdk.internal.dynalink.support.TypeUtilities;
/**
* A factory class for creating {@link DynamicLinker}s. The usual dynamic linker is a linker composed of all
* {@link GuardingDynamicLinker}s known and pre-created by the caller as well as any
- * {@link AutoDiscovery automatically discovered} guarding linkers and the standard fallback
- * {@link BeansLinker} and a {@link DefaultPrelinkFilter}. See {@link DynamicLinker} documentation for tips on
- * how to use this class.
+ * guarding linkers automatically discovered as declared in
+ * {@code /META-INF/services/jdk.internal.dynalink.linker.GuardingDynamicLinker} resources in the classpath (see
+ * {@link ServiceLoader} for the description of this mechanism), and the standard fallback {@link BeansLinker}.
+ * See {@link DynamicLinker} documentation for tips on how to use this class.
*/
public final class DynamicLinkerFactory {
/**
@@ -255,7 +252,8 @@
* Set the pre-link filter. This is a {@link GuardedInvocationFilter} that will get the final chance to modify the
* guarded invocation after it has been created by a component linker and before the dynamic linker links it into
* the call site. It is normally used to adapt the return value type of the invocation to the type of the call site.
- * When not set explicitly, {@link DefaultPrelinkFilter} will be used.
+ * When not set explicitly, a default pre-link filter will be used that simply calls
+ * {@link GuardedInvocation#asType(LinkerServices, java.lang.invoke.MethodType)}
* @param prelinkFilter the pre-link filter for the dynamic linker.
*/
public void setPrelinkFilter(final GuardedInvocationFilter prelinkFilter) {
@@ -317,7 +315,12 @@
addClasses(knownLinkerClasses, fallbackLinkers);
final ClassLoader effectiveClassLoader = classLoaderExplicitlySet ? classLoader : getThreadContextClassLoader();
- final List<GuardingDynamicLinker> discovered = AutoDiscovery.loadLinkers(effectiveClassLoader);
+ final List<GuardingDynamicLinker> discovered = new LinkedList<>();
+ final ServiceLoader<GuardingDynamicLinker> linkerLoader = ServiceLoader.load(GuardingDynamicLinker.class, effectiveClassLoader);
+ for(final GuardingDynamicLinker linker: linkerLoader) {
+ discovered.add(linker);
+ }
+
// Now, concatenate ...
final List<GuardingDynamicLinker> linkers =
new ArrayList<>(prioritizedLinkers.size() + discovered.size()
@@ -336,7 +339,7 @@
final GuardingDynamicLinker composite;
switch(linkers.size()) {
case 0: {
- composite = BottomGuardingDynamicLinker.INSTANCE;
+ composite = (r, s) -> null; // linker that can't link anything
break;
}
case 1: {
@@ -357,7 +360,7 @@
}
if(prelinkFilter == null) {
- prelinkFilter = new DefaultPrelinkFilter();
+ prelinkFilter = (inv, request, linkerServices) -> inv.asType(linkerServices, request.getCallSiteDescriptor().getMethodType());
}
return new DynamicLinker(new LinkerServicesImpl(new TypeConverterFactory(typeConverters,
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/GuardedInvocationFilter.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/GuardedInvocationFilter.java
index 8560d82..23a0a90 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/GuardedInvocationFilter.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/GuardedInvocationFilter.java
@@ -91,6 +91,7 @@
* Interface for objects that are used to transform one guarded invocation into another one. Typical usage is for
* implementing {@link DynamicLinkerFactory#setPrelinkFilter(GuardedInvocationFilter) pre-link filters}.
*/
+@FunctionalInterface
public interface GuardedInvocationFilter {
/**
* Given a guarded invocation, return a potentially different guarded invocation.
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/LinkerServicesImpl.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/LinkerServicesImpl.java
similarity index 90%
rename from nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/LinkerServicesImpl.java
rename to nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/LinkerServicesImpl.java
index 51165a4..4188ade 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/LinkerServicesImpl.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/LinkerServicesImpl.java
@@ -81,7 +81,7 @@
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-package jdk.internal.dynalink.support;
+package jdk.internal.dynalink;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
@@ -95,8 +95,7 @@
/**
* Default implementation of the {@link LinkerServices} interface.
*/
-public class LinkerServicesImpl implements LinkerServices {
-
+final class LinkerServicesImpl implements LinkerServices {
private static final RuntimePermission GET_CURRENT_LINK_REQUEST = new RuntimePermission("dynalink.getCurrentLinkRequest");
private static final ThreadLocal<LinkRequest> threadLinkRequest = new ThreadLocal<>();
@@ -112,7 +111,7 @@
* @param internalObjectsFilter a method handle transformer that is supposed to act as the implementation of this
* services' {@link #filterInternalObjects(java.lang.invoke.MethodHandle)} method.
*/
- public LinkerServicesImpl(final TypeConverterFactory typeConverterFactory,
+ LinkerServicesImpl(final TypeConverterFactory typeConverterFactory,
final GuardingDynamicLinker topLevelLinker, final MethodHandleTransformer internalObjectsFilter) {
this.typeConverterFactory = typeConverterFactory;
this.topLevelLinker = topLevelLinker;
@@ -155,17 +154,14 @@
return internalObjectsFilter != null ? internalObjectsFilter.transform(target) : target;
}
- /**
- * Returns the currently processed link request, or null if the method is invoked outside of the linking process.
- * @return the currently processed link request, or null.
- * @throws SecurityException if the calling code doesn't have the {@code "dynalink.getCurrentLinkRequest"} runtime
- * permission.
- */
- public static LinkRequest getCurrentLinkRequest() {
- final SecurityManager sm = System.getSecurityManager();
- if(sm != null) {
- sm.checkPermission(GET_CURRENT_LINK_REQUEST);
+ static LinkRequest getCurrentLinkRequest() {
+ final LinkRequest currentRequest = threadLinkRequest.get();
+ if (currentRequest != null) {
+ final SecurityManager sm = System.getSecurityManager();
+ if(sm != null) {
+ sm.checkPermission(GET_CURRENT_LINK_REQUEST);
+ }
}
- return threadLinkRequest.get();
+ return currentRequest;
}
}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/TypeConverterFactory.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/TypeConverterFactory.java
similarity index 96%
rename from nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/TypeConverterFactory.java
rename to nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/TypeConverterFactory.java
index 6235ab5..af16e0c 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/TypeConverterFactory.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/TypeConverterFactory.java
@@ -81,7 +81,7 @@
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-package jdk.internal.dynalink.support;
+package jdk.internal.dynalink;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
@@ -98,13 +98,14 @@
import jdk.internal.dynalink.linker.GuardingTypeConverterFactory;
import jdk.internal.dynalink.linker.LinkerServices;
import jdk.internal.dynalink.linker.MethodTypeConversionStrategy;
+import jdk.internal.dynalink.support.TypeUtilities;
/**
* A factory for type converters. This class is the main implementation behind the
* {@link LinkerServices#asType(MethodHandle, MethodType)}. It manages the known {@link GuardingTypeConverterFactory}
* instances and creates appropriate converters for method handles.
*/
-public class TypeConverterFactory {
+final class TypeConverterFactory {
private final GuardingTypeConverterFactory[] factories;
private final ConversionComparator[] comparators;
@@ -193,7 +194,7 @@
* only be ones that can be subjected to method invocation conversions. Can be null, in which case no
* custom strategy is employed.
*/
- public TypeConverterFactory(final Iterable<? extends GuardingTypeConverterFactory> factories,
+ TypeConverterFactory(final Iterable<? extends GuardingTypeConverterFactory> factories,
final MethodTypeConversionStrategy autoConversionStrategy) {
final List<GuardingTypeConverterFactory> l = new LinkedList<>();
final List<ConversionComparator> c = new LinkedList<>();
@@ -226,7 +227,7 @@
* {@link MethodHandles#filterArguments(MethodHandle, int, MethodHandle...)} with
* {@link GuardingTypeConverterFactory} produced type converters as filters.
*/
- public MethodHandle asType(final MethodHandle handle, final MethodType fromType) {
+ MethodHandle asType(final MethodHandle handle, final MethodType fromType) {
MethodHandle newHandle = handle;
final MethodType toType = newHandle.type();
final int l = toType.parameterCount();
@@ -295,7 +296,7 @@
* @param to the target type for the conversion
* @return true if there can be a conversion, false if there can not.
*/
- public boolean canConvert(final Class<?> from, final Class<?> to) {
+ boolean canConvert(final Class<?> from, final Class<?> to) {
return canAutoConvert(from, to) || canConvert.get(from).get(to);
}
@@ -309,7 +310,7 @@
* @return one of Comparison constants that establish which - if any - of the target types is preferable for the
* conversion.
*/
- public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
+ Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
for(final ConversionComparator comparator: comparators) {
final Comparison result = comparator.compareConversion(sourceType, targetType1, targetType2);
if(result != Comparison.INDETERMINATE) {
@@ -363,7 +364,7 @@
* @param targetType the type to convert to
* @return a method handle performing the conversion.
*/
- public MethodHandle getTypeConverter(final Class<?> sourceType, final Class<?> targetType) {
+ MethodHandle getTypeConverter(final Class<?> sourceType, final Class<?> targetType) {
try {
return converterIdentityMap.get(sourceType).get(targetType);
} catch(final NotCacheableConverter e) {
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/AbstractJavaLinker.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/AbstractJavaLinker.java
index f42e0bc..9a8159d 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/AbstractJavaLinker.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/AbstractJavaLinker.java
@@ -103,10 +103,10 @@
import jdk.internal.dynalink.linker.GuardingDynamicLinker;
import jdk.internal.dynalink.linker.LinkRequest;
import jdk.internal.dynalink.linker.LinkerServices;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.internal.dynalink.support.Guards;
import jdk.internal.dynalink.support.Lookup;
import jdk.internal.dynalink.support.TypeUtilities;
+import sun.reflect.CallerSensitive;
/**
* A base class for both {@link StaticClassLinker} and {@link BeanLinker}. Deals with common aspects of property
@@ -284,7 +284,7 @@
* @return the single dynamic method representing the reflective member
*/
private static SingleDynamicMethod createDynamicMethod(final AccessibleObject m) {
- if(CallerSensitiveDetector.isCallerSensitive(m)) {
+ if (m.isAnnotationPresent(CallerSensitive.class)) {
// Method has @CallerSensitive annotation
return new CallerSensitiveDynamicMethod(m);
}
@@ -350,7 +350,7 @@
if("callMethod" == op) {
return getCallPropWithThis(callSiteDescriptor, linkerServices);
}
- List<String> operations = CallSiteDescriptorFactory.tokenizeOperators(callSiteDescriptor);
+ List<String> operations = callSiteDescriptor.tokenizeOperators();
while(!operations.isEmpty()) {
final GuardedInvocationComponent gic = getGuardedInvocationComponent(callSiteDescriptor, linkerServices,
operations);
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/CallerSensitiveDetector.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/CallerSensitiveDetector.java
deleted file mode 100644
index e4ada35..0000000
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/CallerSensitiveDetector.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * This file is available under and governed by the GNU General Public
- * License version 2 only, as published by the Free Software Foundation.
- * However, the following notice accompanied the original version of this
- * file, and Oracle licenses the original version of this file under the BSD
- * license:
- */
-/*
- Copyright 2009-2013 Attila Szegedi
-
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion.
-
- You may not use this file except in compliance with either the Apache
- License or the BSD License.
-
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you:
-
- You may obtain a copy of the Apache License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied. See the License for the specific language governing
- permissions and limitations under the License.
-
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you:
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the copyright holder nor the names of
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package jdk.internal.dynalink.beans;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AccessibleObject;
-import sun.reflect.CallerSensitive;
-
-/**
- * Utility class that determines if a method or constructor is caller sensitive. It actually encapsulates two different
- * strategies for determining caller sensitivity; a more robust one that works if Dynalink runs as code with access
- * to {@code sun.reflect} package, and an unprivileged one that is used when Dynalink doesn't have access to that
- * package. Note that even the unprivileged strategy is ordinarily robust, but it relies on the {@code toString} method
- * of the annotation. If an attacker were to use a different annotation to spoof the string representation of the
- * {@code CallerSensitive} annotation, they could designate their own methods as caller sensitive. This however does not
- * escalate privileges, only causes Dynalink to never cache method handles for such methods, so all it would do would
- * decrease the performance in linking such methods. In the opposite case when an attacker could trick Dynalink into not
- * recognizing genuine {@code CallerSensitive} annotations, Dynalink would treat caller sensitive methods as ordinary
- * methods, and would cache them bound to a zero-privilege delegate as the caller (just what Dynalink did before it
- * could handle caller-sensitive methods). That would practically render caller-sensitive methods exposed through
- * Dynalink unusable, but again, can not lead to any privilege escalations. Therefore, even the less robust unprivileged
- * strategy is safe; the worst thing a successful attack against it can achieve is slight reduction in Dynalink-exposed
- * functionality or performance.
- */
-public class CallerSensitiveDetector {
-
- private static final DetectionStrategy DETECTION_STRATEGY = getDetectionStrategy();
-
- static boolean isCallerSensitive(final AccessibleObject ao) {
- return DETECTION_STRATEGY.isCallerSensitive(ao);
- }
-
- private static DetectionStrategy getDetectionStrategy() {
- try {
- return new PrivilegedDetectionStrategy();
- } catch(final Throwable t) {
- return new UnprivilegedDetectionStrategy();
- }
- }
-
- private abstract static class DetectionStrategy {
- abstract boolean isCallerSensitive(AccessibleObject ao);
- }
-
- private static class PrivilegedDetectionStrategy extends DetectionStrategy {
- private static final Class<? extends Annotation> CALLER_SENSITIVE_ANNOTATION_CLASS = CallerSensitive.class;
-
- @Override
- boolean isCallerSensitive(final AccessibleObject ao) {
- return ao.getAnnotation(CALLER_SENSITIVE_ANNOTATION_CLASS) != null;
- }
- }
-
- private static class UnprivilegedDetectionStrategy extends DetectionStrategy {
- private static final String CALLER_SENSITIVE_ANNOTATION_STRING = "@sun.reflect.CallerSensitive()";
-
- @Override
- boolean isCallerSensitive(final AccessibleObject o) {
- for(final Annotation a: o.getAnnotations()) {
- if(String.valueOf(a).equals(CALLER_SENSITIVE_ANNOTATION_STRING)) {
- return true;
- }
- }
- return false;
- }
- }
-}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/DynamicMethodLinker.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/DynamicMethodLinker.java
index 7067c2c..083d45b 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/DynamicMethodLinker.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/DynamicMethodLinker.java
@@ -90,7 +90,6 @@
import jdk.internal.dynalink.linker.LinkRequest;
import jdk.internal.dynalink.linker.LinkerServices;
import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.internal.dynalink.support.Guards;
/**
@@ -119,8 +118,8 @@
final MethodHandle invocation;
if (operator == "call" && !constructor) {
- invocation = dynMethod.getInvocation(
- CallSiteDescriptorFactory.dropParameterTypes(desc, 0, 1), linkerServices);
+ invocation = dynMethod.getInvocation(desc.changeMethodType(
+ desc.getMethodType().dropParameterTypes(0, 1)), linkerServices);
} else if (operator == "new" && constructor) {
final MethodHandle ctorInvocation = dynMethod.getInvocation(desc, linkerServices);
if(ctorInvocation == null) {
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/AbstractCallSiteDescriptor.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/AbstractCallSiteDescriptor.java
index 7e31b4d..398e8bcbc 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/AbstractCallSiteDescriptor.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/AbstractCallSiteDescriptor.java
@@ -99,11 +99,6 @@
return appendName(new StringBuilder(getNameLength())).toString();
}
- @Override
- public Lookup getLookup() {
- return MethodHandles.publicLookup();
- }
-
@Override
public boolean equals(final Object obj) {
return obj instanceof CallSiteDescriptor && equals((CallSiteDescriptor)obj);
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/AutoDiscovery.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/AutoDiscovery.java
deleted file mode 100644
index ba31861..0000000
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/AutoDiscovery.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * This file is available under and governed by the GNU General Public
- * License version 2 only, as published by the Free Software Foundation.
- * However, the following notice accompanied the original version of this
- * file, and Oracle licenses the original version of this file under the BSD
- * license:
- */
-/*
- Copyright 2009-2013 Attila Szegedi
-
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion.
-
- You may not use this file except in compliance with either the Apache
- License or the BSD License.
-
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you:
-
- You may obtain a copy of the Apache License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied. See the License for the specific language governing
- permissions and limitations under the License.
-
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you:
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the copyright holder nor the names of
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package jdk.internal.dynalink.support;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.ServiceLoader;
-import jdk.internal.dynalink.DynamicLinkerFactory;
-import jdk.internal.dynalink.linker.GuardingDynamicLinker;
-
-/**
- * Provides methods for automatic discovery of all guarding dynamic linkers listed in the
- * <tt>/META-INF/services/jdk.internal.dynalink.linker.GuardingDynamicLinker</tt> resources of all JAR files for a
- * particular class loader. Ordinarily, you will not use this class directly, but you will use a
- * {@link DynamicLinkerFactory} instead.
- */
-public class AutoDiscovery {
-
- private AutoDiscovery() {
- }
-
- /**
- * Discovers all guarding dynamic linkers listed in JAR files of the context class loader of the current thread.
- *
- * @return a list of available linkers. Can be zero-length list but not null.
- */
- public static List<GuardingDynamicLinker> loadLinkers() {
- return getLinkers(ServiceLoader.load(GuardingDynamicLinker.class));
- }
-
- /**
- * Discovers all guarding dynamic linkers listed in JAR files of the specified class loader.
- *
- * @param cl the class loader to use
- * @return a list of guarding dynamic linkers available through the specified class loader. Can be zero-length list
- * but not null.
- */
- public static List<GuardingDynamicLinker> loadLinkers(final ClassLoader cl) {
- return getLinkers(ServiceLoader.load(GuardingDynamicLinker.class, cl));
- }
-
- /**
- * I can't believe there's no Collections API for making a List given an Iterator...
- */
- private static <T> List<T> getLinkers(final ServiceLoader<T> loader) {
- final List<T> list = new LinkedList<>();
- for(final T linker: loader) {
- list.add(linker);
- }
- return list;
- }
-}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/BottomGuardingDynamicLinker.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/BottomGuardingDynamicLinker.java
deleted file mode 100644
index cb407e1..0000000
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/BottomGuardingDynamicLinker.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * This file is available under and governed by the GNU General Public
- * License version 2 only, as published by the Free Software Foundation.
- * However, the following notice accompanied the original version of this
- * file, and Oracle licenses the original version of this file under the BSD
- * license:
- */
-/*
- Copyright 2009-2013 Attila Szegedi
-
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion.
-
- You may not use this file except in compliance with either the Apache
- License or the BSD License.
-
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you:
-
- You may obtain a copy of the Apache License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied. See the License for the specific language governing
- permissions and limitations under the License.
-
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you:
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the copyright holder nor the names of
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package jdk.internal.dynalink.support;
-
-import jdk.internal.dynalink.linker.GuardedInvocation;
-import jdk.internal.dynalink.linker.LinkRequest;
-import jdk.internal.dynalink.linker.LinkerServices;
-import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
-
-/**
- * A linker that can't link any call site. Only used internally by {@link CompositeTypeBasedGuardingDynamicLinker}. Can
- * be used by other language runtimes if they need it though.
- */
-public class BottomGuardingDynamicLinker implements TypeBasedGuardingDynamicLinker {
-
- /**
- * The sole instance of this stateless linker.
- */
- public static final BottomGuardingDynamicLinker INSTANCE = new BottomGuardingDynamicLinker();
-
- private BottomGuardingDynamicLinker() {
- }
-
- @Override
- public boolean canLinkType(final Class<?> type) {
- return false;
- }
-
- @Override
- public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) {
- return null;
- }
-}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CallSiteDescriptorFactory.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CallSiteDescriptorFactory.java
deleted file mode 100644
index 7d136ca..0000000
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CallSiteDescriptorFactory.java
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * This file is available under and governed by the GNU General Public
- * License version 2 only, as published by the Free Software Foundation.
- * However, the following notice accompanied the original version of this
- * file, and Oracle licenses the original version of this file under the BSD
- * license:
- */
-/*
- Copyright 2009-2013 Attila Szegedi
-
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion.
-
- You may not use this file except in compliance with either the Apache
- License or the BSD License.
-
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you:
-
- You may obtain a copy of the Apache License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied. See the License for the specific language governing
- permissions and limitations under the License.
-
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you:
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the copyright holder nor the names of
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package jdk.internal.dynalink.support;
-
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodHandles.Lookup;
-import java.lang.invoke.MethodType;
-import java.lang.ref.Reference;
-import java.lang.ref.WeakReference;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import java.util.StringTokenizer;
-import java.util.WeakHashMap;
-import jdk.internal.dynalink.CallSiteDescriptor;
-
-/**
- * Usable as a default factory for call site descriptor implementations. It is weakly canonicalizing, meaning
- * it will return the same immutable call site descriptor for identical inputs, i.e. repeated requests for a
- * descriptor signifying public lookup for {@code "dyn:getProp:color"} of type {@code Object(Object)} will
- * return the same object as long as a previously created, at least softly reachable one exists. It also uses
- * several different implementations of the {@link CallSiteDescriptor} internally, and chooses the most
- * space-efficient one based on the input.
- */
-public class CallSiteDescriptorFactory {
- private static final WeakHashMap<CallSiteDescriptor, Reference<CallSiteDescriptor>> publicDescs =
- new WeakHashMap<>();
-
-
- private CallSiteDescriptorFactory() {
- }
-
- /**
- * Creates a new call site descriptor instance. The actual underlying class of the instance is dependent on the
- * passed arguments to be space efficient; i.e. if you only use the public lookup, you'll get back an
- * implementation that doesn't waste space on storing the lookup object.
- * @param lookup the lookup that determines access rights at the call site. If your language runtime doesn't have
- * equivalents of Java access concepts, just use {@link MethodHandles#publicLookup()}. Must not be null.
- * @param name the name of the method at the call site. Must not be null.
- * @param methodType the type of the method at the call site. Must not be null.
- * @return a call site descriptor representing the input. Note that although the method name is "create", it will
- * in fact return a weakly-referenced canonical instance.
- */
- public static CallSiteDescriptor create(final Lookup lookup, final String name, final MethodType methodType) {
- Objects.requireNonNull(name);
- Objects.requireNonNull(methodType);
- Objects.requireNonNull(lookup);
- final String[] tokenizedName = tokenizeName(name);
- if(isPublicLookup(lookup)) {
- return getCanonicalPublicDescriptor(createPublicCallSiteDescriptor(tokenizedName, methodType));
- }
- return new LookupCallSiteDescriptor(tokenizedName, methodType, lookup);
- }
-
- static CallSiteDescriptor getCanonicalPublicDescriptor(final CallSiteDescriptor desc) {
- synchronized(publicDescs) {
- final Reference<CallSiteDescriptor> ref = publicDescs.get(desc);
- if(ref != null) {
- final CallSiteDescriptor canonical = ref.get();
- if(canonical != null) {
- return canonical;
- }
- }
- publicDescs.put(desc, createReference(desc));
- }
- return desc;
- }
-
- /**
- * Override this to use a different kind of references for the cache
- * @param desc desc
- * @return reference
- */
- protected static Reference<CallSiteDescriptor> createReference(final CallSiteDescriptor desc) {
- return new WeakReference<>(desc);
- }
-
- private static CallSiteDescriptor createPublicCallSiteDescriptor(final String[] tokenizedName, final MethodType methodType) {
- final int l = tokenizedName.length;
- if(l > 0 && tokenizedName[0] == "dyn") {
- if(l == 2) {
- return new UnnamedDynCallSiteDescriptor(tokenizedName[1], methodType);
- } if (l == 3) {
- return new NamedDynCallSiteDescriptor(tokenizedName[1], tokenizedName[2], methodType);
- }
- }
- return new DefaultCallSiteDescriptor(tokenizedName, methodType);
- }
-
- private static boolean isPublicLookup(final Lookup lookup) {
- return lookup == MethodHandles.publicLookup();
- }
-
- /**
- * Tokenizes the composite name along colons, as well as {@link NameCodec#decode(String) demangles} and interns
- * the tokens. The first two tokens are not demangled as they are supposed to be the naming scheme and the name of
- * the operation which can be expected to consist of just alphabetical characters.
- * @param name the composite name consisting of colon-separated, possibly mangled tokens.
- * @return an array of tokens
- */
- public static String[] tokenizeName(final String name) {
- final StringTokenizer tok = new StringTokenizer(name, CallSiteDescriptor.TOKEN_DELIMITER);
- final String[] tokens = new String[tok.countTokens()];
- for(int i = 0; i < tokens.length; ++i) {
- String token = tok.nextToken();
- if(i > 1) {
- token = NameCodec.decode(token);
- }
- tokens[i] = token.intern();
- }
- return tokens;
- }
-
- /**
- * Tokenizes a composite operation name along pipe characters. I.e. if you have a "dyn:getElem|getProp|getMethod"
- * operation, returns a list of ["getElem", "getProp", "getMethod"]. The tokens are not interned.
- * @param desc the call site descriptor with the operation
- * @return a list of tokens
- */
- public static List<String> tokenizeOperators(final CallSiteDescriptor desc) {
- final String ops = desc.getNameToken(CallSiteDescriptor.OPERATOR);
- final StringTokenizer tok = new StringTokenizer(ops, CallSiteDescriptor.OPERATOR_DELIMITER);
- final int count = tok.countTokens();
- if(count == 1) {
- return Collections.singletonList(ops);
- }
- final String[] tokens = new String[count];
- for(int i = 0; i < count; ++i) {
- tokens[i] = tok.nextToken();
- }
- return Arrays.asList(tokens);
- }
-
- /**
- * Returns a new call site descriptor that is identical to the passed one, except that it has some parameter types
- * removed from its method type.
- * @param desc the original call site descriptor
- * @param start index of the first parameter to remove
- * @param end index of the first parameter to not remove
- * @return a new call site descriptor with modified method type
- */
- public static CallSiteDescriptor dropParameterTypes(final CallSiteDescriptor desc, final int start, final int end) {
- return desc.changeMethodType(desc.getMethodType().dropParameterTypes(start, end));
- }
-
- /**
- * Returns a new call site descriptor that is identical to the passed one, except that it has a single parameter
- * type changed in its method type.
- * @param desc the original call site descriptor
- * @param num index of the parameter to change
- * @param nptype the new parameter type
- * @return a new call site descriptor with modified method type
- */
- public static CallSiteDescriptor changeParameterType(final CallSiteDescriptor desc, final int num, final Class<?> nptype) {
- return desc.changeMethodType(desc.getMethodType().changeParameterType(num, nptype));
- }
-
- /**
- * Returns a new call site descriptor that is identical to the passed one, except that it has the return type
- * changed in its method type.
- * @param desc the original call site descriptor
- * @param nrtype the new return type
- * @return a new call site descriptor with modified method type
- */
- public static CallSiteDescriptor changeReturnType(final CallSiteDescriptor desc, final Class<?> nrtype) {
- return desc.changeMethodType(desc.getMethodType().changeReturnType(nrtype));
- }
-
- /**
- * Returns a new call site descriptor that is identical to the passed one, except that it has additional parameter
- * types inserted into its method type.
- * @param desc the original call site descriptor
- * @param num index at which the new parameters are inserted
- * @param ptypesToInsert the new types to insert
- * @return a new call site descriptor with modified method type
- */
- public static CallSiteDescriptor insertParameterTypes(final CallSiteDescriptor desc, final int num, final Class<?>... ptypesToInsert) {
- return desc.changeMethodType(desc.getMethodType().insertParameterTypes(num, ptypesToInsert));
- }
-
- /**
- * Returns a new call site descriptor that is identical to the passed one, except that it has additional parameter
- * types inserted into its method type.
- * @param desc the original call site descriptor
- * @param num index at which the new parameters are inserted
- * @param ptypesToInsert the new types to insert
- * @return a new call site descriptor with modified method type
- */
- public static CallSiteDescriptor insertParameterTypes(final CallSiteDescriptor desc, final int num, final List<Class<?>> ptypesToInsert) {
- return desc.changeMethodType(desc.getMethodType().insertParameterTypes(num, ptypesToInsert));
- }
-}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/DefaultPrelinkFilter.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/DefaultPrelinkFilter.java
deleted file mode 100644
index ad9679f..0000000
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/DefaultPrelinkFilter.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * This file is available under and governed by the GNU General Public
- * License version 2 only, as published by the Free Software Foundation.
- * However, the following notice accompanied the original version of this
- * file, and Oracle licenses the original version of this file under the BSD
- * license:
- */
-/*
- Copyright 2009-2013 Attila Szegedi
-
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion.
-
- You may not use this file except in compliance with either the Apache
- License or the BSD License.
-
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you:
-
- You may obtain a copy of the Apache License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied. See the License for the specific language governing
- permissions and limitations under the License.
-
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you:
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the copyright holder nor the names of
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package jdk.internal.dynalink.support;
-
-import jdk.internal.dynalink.GuardedInvocationFilter;
-import jdk.internal.dynalink.linker.GuardedInvocation;
-import jdk.internal.dynalink.linker.LinkRequest;
-import jdk.internal.dynalink.linker.LinkerServices;
-
-/**
- * Default filter for guarded invocation pre link filtering
- */
-public class DefaultPrelinkFilter implements GuardedInvocationFilter {
- @Override
- public GuardedInvocation filter(final GuardedInvocation inv, final LinkRequest request, final LinkerServices linkerServices) {
- return inv.asType(linkerServices, request.getCallSiteDescriptor().getMethodType());
- }
-}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/Guards.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/Guards.java
index 2b0256e..e312cd0 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/Guards.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/Guards.java
@@ -92,10 +92,9 @@
import jdk.internal.dynalink.linker.LinkerServices;
/**
- * Utility methods for creating typical guards. TODO: introduce reasonable caching of created guards.
- *
+ * Utility methods for creating typical guards.
*/
-public class Guards {
+public final class Guards {
private static final Logger LOG = Logger
.getLogger(Guards.class.getName(), "jdk.internal.dynalink.support.messages");
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/LookupCallSiteDescriptor.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/LookupCallSiteDescriptor.java
deleted file mode 100644
index 7e24033..0000000
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/LookupCallSiteDescriptor.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * This file is available under and governed by the GNU General Public
- * License version 2 only, as published by the Free Software Foundation.
- * However, the following notice accompanied the original version of this
- * file, and Oracle licenses the original version of this file under the BSD
- * license:
- */
-/*
- Copyright 2009-2013 Attila Szegedi
-
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion.
-
- You may not use this file except in compliance with either the Apache
- License or the BSD License.
-
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you:
-
- You may obtain a copy of the Apache License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied. See the License for the specific language governing
- permissions and limitations under the License.
-
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you:
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the copyright holder nor the names of
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package jdk.internal.dynalink.support;
-
-import java.lang.invoke.MethodHandles.Lookup;
-import java.lang.invoke.MethodType;
-import jdk.internal.dynalink.CallSiteDescriptor;
-
-/**
- * A call site descriptor that stores a specific {@link Lookup}. It does not, however, store static bootstrap arguments.
- */
-class LookupCallSiteDescriptor extends DefaultCallSiteDescriptor {
- private final Lookup lookup;
-
- /**
- * Create a new call site descriptor from explicit information.
- * @param tokenizedName the name of the method
- * @param methodType the method type
- * @param lookup the lookup
- */
- LookupCallSiteDescriptor(final String[] tokenizedName, final MethodType methodType, final Lookup lookup) {
- super(tokenizedName, methodType);
- this.lookup = lookup;
- }
-
- @Override
- public Lookup getLookup() {
- return lookup;
- }
-
- @Override
- public CallSiteDescriptor changeMethodType(final MethodType newMethodType) {
- return new LookupCallSiteDescriptor(getTokenizedName(), newMethodType, lookup);
- }
-}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/NameCodec.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/NameCodec.java
index 179531f..d36f739 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/NameCodec.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/NameCodec.java
@@ -94,7 +94,7 @@
* individual tokens, and not the whole name at the call site, i.e. the colon character normally separating the tokens
* is never mangled. I.e. you wouldn't mangle {@code dyn:getProp:color} into {@code dyn\!getProp\!color}, but you would
* mangle {@code dyn:getProp:color$} into {@code dyn:getProp:\=color\%} (only mangling the individual token containing
- * the symbol {@code color$}). {@link CallSiteDescriptorFactory#tokenizeName(String)} (and by implication, all call site
+ * the symbol {@code color$}). {@link CallSiteDescriptor#tokenizeName(String)} (and by implication, all call site
* descriptors it creates) will automatically perform demangling on the passed names. If you use this factory, or you
* have your own way of creating call site descriptors, but you still delegate to this method of the default factory
* (it is recommended that you do), then you have demangling handled for you already, and only need to ensure that you
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/NamedDynCallSiteDescriptor.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/NamedDynCallSiteDescriptor.java
deleted file mode 100644
index 817df52..0000000
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/NamedDynCallSiteDescriptor.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * This file is available under and governed by the GNU General Public
- * License version 2 only, as published by the Free Software Foundation.
- * However, the following notice accompanied the original version of this
- * file, and Oracle licenses the original version of this file under the BSD
- * license:
- */
-/*
- Copyright 2009-2013 Attila Szegedi
-
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion.
-
- You may not use this file except in compliance with either the Apache
- License or the BSD License.
-
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you:
-
- You may obtain a copy of the Apache License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied. See the License for the specific language governing
- permissions and limitations under the License.
-
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you:
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the copyright holder nor the names of
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package jdk.internal.dynalink.support;
-
-import java.lang.invoke.MethodType;
-import jdk.internal.dynalink.CallSiteDescriptor;
-
-class NamedDynCallSiteDescriptor extends UnnamedDynCallSiteDescriptor {
- private final String name;
-
- NamedDynCallSiteDescriptor(final String op, final String name, final MethodType methodType) {
- super(op, methodType);
- this.name = name;
- }
-
- @Override
- public int getNameTokenCount() {
- return 3;
- }
-
- @Override
- public String getNameToken(final int i) {
- switch(i) {
- case 0: return "dyn";
- case 1: return getOp();
- case 2: return name;
- default: throw new IndexOutOfBoundsException(String.valueOf(i));
- }
- }
-
- @Override
- public CallSiteDescriptor changeMethodType(final MethodType newMethodType) {
- return CallSiteDescriptorFactory.getCanonicalPublicDescriptor(new NamedDynCallSiteDescriptor(getOp(), name,
- newMethodType));
- }
-}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/RuntimeContextLinkRequestImpl.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/RuntimeContextLinkRequestImpl.java
index 528bed7..aecbbae 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/RuntimeContextLinkRequestImpl.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/RuntimeContextLinkRequestImpl.java
@@ -119,9 +119,10 @@
@Override
public LinkRequest withoutRuntimeContext() {
if(contextStrippedRequest == null) {
+ final CallSiteDescriptor desc = getCallSiteDescriptor();
contextStrippedRequest =
- new LinkRequestImpl(CallSiteDescriptorFactory.dropParameterTypes(getCallSiteDescriptor(), 1,
- runtimeContextArgCount + 1), getCallSiteToken(), getLinkCount(), isCallSiteUnstable(), getTruncatedArguments());
+ new LinkRequestImpl(desc.changeMethodType(desc.getMethodType().dropParameterTypes(1, runtimeContextArgCount + 1)),
+ getCallSiteToken(), getLinkCount(), isCallSiteUnstable(), getTruncatedArguments());
}
return contextStrippedRequest;
}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/DefaultCallSiteDescriptor.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/SimpleCallSiteDescriptor.java
similarity index 76%
rename from nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/DefaultCallSiteDescriptor.java
rename to nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/SimpleCallSiteDescriptor.java
index 17cb0c8..be21c70 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/DefaultCallSiteDescriptor.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/SimpleCallSiteDescriptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -31,7 +31,7 @@
* license:
*/
/*
- Copyright 2009-2013 Attila Szegedi
+ Copyright 2015 Attila Szegedi
Licensed under both the Apache License, Version 2.0 (the "Apache License")
and the BSD License (the "BSD License"), with licensee being free to
@@ -85,19 +85,34 @@
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
+import java.security.Permission;
+import java.util.Objects;
import jdk.internal.dynalink.CallSiteDescriptor;
/**
- * A default, fairly light implementation of a call site descriptor used for describing non-standard operations. It does
- * not store {@link Lookup} objects but always returns the public lookup from its {@link #getLookup()} method. If you
- * need to support non-public lookup, you can use {@link LookupCallSiteDescriptor}.
+ * A simple implementation of the call site descriptor. It stores the lookup, the name, and the method type.
*/
-class DefaultCallSiteDescriptor extends AbstractCallSiteDescriptor {
+public class SimpleCallSiteDescriptor extends AbstractCallSiteDescriptor {
+ private static final Permission GET_LOOKUP_PERMISSION = new RuntimePermission("dynalink.getLookup");
+ private final Lookup lookup;
private final String[] tokenizedName;
private final MethodType methodType;
- DefaultCallSiteDescriptor(final String[] tokenizedName, final MethodType methodType) {
+ /**
+ * Creates a new simple call site descriptor.
+ * @param lookup the lookup at the call site, as passed to the bootstrap method. Must not be null.
+ * @param name the name of the operation at the call site, as passed to the bootstrap method. Must not be null.
+ * @param methodType the signature of operation at the call site, as passed to the bootstrap method. Must not be null.
+ */
+ public SimpleCallSiteDescriptor(final Lookup lookup, final String name, final MethodType methodType) {
+ this(Objects.requireNonNull(lookup, "lookup"),
+ CallSiteDescriptor.tokenizeName(Objects.requireNonNull(name, "name")),
+ Objects.requireNonNull(methodType, "methodType"));
+ }
+
+ private SimpleCallSiteDescriptor(final Lookup lookup, final String[] tokenizedName, final MethodType methodType) {
+ this.lookup = lookup;
this.tokenizedName = tokenizedName;
this.methodType = methodType;
}
@@ -116,18 +131,18 @@
}
}
- String[] getTokenizedName() {
- return tokenizedName;
- }
-
@Override
public MethodType getMethodType() {
return methodType;
}
@Override
+ public final Lookup getLookup() {
+ return lookup;
+ }
+
+ @Override
public CallSiteDescriptor changeMethodType(final MethodType newMethodType) {
- return CallSiteDescriptorFactory.getCanonicalPublicDescriptor(new DefaultCallSiteDescriptor(tokenizedName,
- newMethodType));
+ return new SimpleCallSiteDescriptor(lookup, tokenizedName, newMethodType);
}
}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/UnnamedDynCallSiteDescriptor.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/UnnamedDynCallSiteDescriptor.java
deleted file mode 100644
index 89a0677..0000000
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/UnnamedDynCallSiteDescriptor.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * This file is available under and governed by the GNU General Public
- * License version 2 only, as published by the Free Software Foundation.
- * However, the following notice accompanied the original version of this
- * file, and Oracle licenses the original version of this file under the BSD
- * license:
- */
-/*
- Copyright 2009-2013 Attila Szegedi
-
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion.
-
- You may not use this file except in compliance with either the Apache
- License or the BSD License.
-
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you:
-
- You may obtain a copy of the Apache License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied. See the License for the specific language governing
- permissions and limitations under the License.
-
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you:
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the copyright holder nor the names of
- contributors may be used to endorse or promote products derived from
- this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-package jdk.internal.dynalink.support;
-
-import java.lang.invoke.MethodType;
-import jdk.internal.dynalink.CallSiteDescriptor;
-
-class UnnamedDynCallSiteDescriptor extends AbstractCallSiteDescriptor {
- private final MethodType methodType;
- private final String op;
-
- UnnamedDynCallSiteDescriptor(final String op, final MethodType methodType) {
- this.op = op;
- this.methodType = methodType;
- }
-
- @Override
- public int getNameTokenCount() {
- return 2;
- }
-
- String getOp() {
- return op;
- }
-
- @Override
- public String getNameToken(final int i) {
- switch(i) {
- case 0: return "dyn";
- case 1: return op;
- default: throw new IndexOutOfBoundsException(String.valueOf(i));
- }
- }
-
- @Override
- public MethodType getMethodType() {
- return methodType;
- }
-
- @Override
- public CallSiteDescriptor changeMethodType(final MethodType newMethodType) {
- return CallSiteDescriptorFactory.getCanonicalPublicDescriptor(new UnnamedDynCallSiteDescriptor(op,
- newMethodType));
- }
-}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeObject.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeObject.java
index 7dc154e..013d376 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeObject.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeObject.java
@@ -44,7 +44,6 @@
import jdk.internal.dynalink.linker.GuardedInvocation;
import jdk.internal.dynalink.linker.GuardingDynamicLinker;
import jdk.internal.dynalink.linker.LinkRequest;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.internal.dynalink.support.LinkRequestImpl;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
import jdk.nashorn.internal.lookup.Lookup;
@@ -64,6 +63,7 @@
import jdk.nashorn.internal.runtime.linker.Bootstrap;
import jdk.nashorn.internal.runtime.linker.InvokeByName;
import jdk.nashorn.internal.runtime.linker.NashornBeansLinker;
+import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
/**
* ECMA 15.2 Object objects
@@ -834,8 +834,8 @@
}
private static LinkRequest createLinkRequest(final String operation, final MethodType methodType, final Object source) {
- return new LinkRequestImpl(CallSiteDescriptorFactory.create(MethodHandles.publicLookup(), operation,
- methodType), null, 0, false, source);
+ return new LinkRequestImpl(NashornCallSiteDescriptor.get(MethodHandles.publicLookup(), operation,
+ methodType, 0), null, 0, false, source);
}
private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java
index 5d47305..e842da0 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptObject.java
@@ -68,7 +68,6 @@
import jdk.internal.dynalink.CallSiteDescriptor;
import jdk.internal.dynalink.linker.GuardedInvocation;
import jdk.internal.dynalink.linker.LinkRequest;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.nashorn.internal.codegen.CompilerConstants.Call;
import jdk.nashorn.internal.codegen.ObjectClassGenerator;
import jdk.nashorn.internal.codegen.types.Type;
@@ -1840,7 +1839,7 @@
// JavaScript is "immune" to all currently defined Dynalink composite operation - getProp is the same as getElem
// is the same as getMethod as JavaScript objects have a single namespace for all three. Therefore, we don't
// care about them, and just link to whatever is the first operation.
- final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);
+ final String operator = desc.tokenizeOperators().get(0);
// NOTE: we support getElem and setItem as JavaScript doesn't distinguish items from properties. Nashorn itself
// emits "dyn:getProp:identifier" for "<expr>.<identifier>" and "dyn:getElem" for "<expr>[<expr>]", but we are
// more flexible here and dispatch not on operation name (getProp vs. getElem), but rather on whether the
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Undefined.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Undefined.java
index db26bcd..121bc3a 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Undefined.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Undefined.java
@@ -32,7 +32,6 @@
import java.lang.invoke.MethodHandles;
import jdk.internal.dynalink.CallSiteDescriptor;
import jdk.internal.dynalink.linker.GuardedInvocation;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.internal.dynalink.support.Guards;
import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
@@ -92,7 +91,7 @@
* @return GuardedInvocation to be invoked at call site.
*/
public static GuardedInvocation lookup(final CallSiteDescriptor desc) {
- final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);
+ final String operator = desc.tokenizeOperators().get(0);
switch (operator) {
case "new":
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/WithObject.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/WithObject.java
index 1780e3f..02d0961 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/WithObject.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/WithObject.java
@@ -35,7 +35,6 @@
import jdk.internal.dynalink.CallSiteDescriptor;
import jdk.internal.dynalink.linker.GuardedInvocation;
import jdk.internal.dynalink.linker.LinkRequest;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.nashorn.api.scripting.AbstractJSObject;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor;
@@ -137,7 +136,7 @@
if (self != null) {
final String fallBack;
- final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);
+ final String operator = desc.tokenizeOperators().get(0);
switch (operator) {
case "callMethod":
@@ -211,7 +210,7 @@
@Override
protected Object invokeNoSuchProperty(final String name, final boolean isScope, final int programPoint) {
- FindProperty find = expression.findProperty(NO_SUCH_PROPERTY_NAME, true);
+ final FindProperty find = expression.findProperty(NO_SUCH_PROPERTY_NAME, true);
if (find != null) {
final Object func = find.getObjectValue();
if (func instanceof ScriptFunction) {
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java
index 2e025a5..e1e54fa 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java
@@ -39,7 +39,6 @@
import jdk.internal.dynalink.linker.LinkRequest;
import jdk.internal.dynalink.linker.LinkerServices;
import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.nashorn.internal.lookup.MethodHandleFactory;
import jdk.nashorn.internal.lookup.MethodHandleFunctionality;
import jdk.nashorn.internal.runtime.JSType;
@@ -119,12 +118,12 @@
}
private GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request, final LinkerServices linkerServices) throws Exception {
- final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);
+ final String operator = desc.tokenizeOperators().get(0);
final int c = desc.getNameTokenCount();
GuardedInvocation inv;
try {
inv = nashornBeansLinker.getGuardedInvocation(request, linkerServices);
- } catch (Throwable th) {
+ } catch (final Throwable th) {
inv = null;
}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JSObjectLinker.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JSObjectLinker.java
index 8fd28cc..250e1a2 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JSObjectLinker.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JSObjectLinker.java
@@ -36,7 +36,6 @@
import jdk.internal.dynalink.linker.LinkRequest;
import jdk.internal.dynalink.linker.LinkerServices;
import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.nashorn.api.scripting.JSObject;
import jdk.nashorn.internal.lookup.MethodHandleFactory;
import jdk.nashorn.internal.lookup.MethodHandleFunctionality;
@@ -94,7 +93,7 @@
}
private GuardedInvocation lookup(final CallSiteDescriptor desc, final LinkRequest request, final LinkerServices linkerServices) throws Exception {
- final String operator = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);
+ final String operator = desc.tokenizeOperators().get(0);
final int c = desc.getNameTokenCount();
switch (operator) {
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaSuperAdapterLinker.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaSuperAdapterLinker.java
index 9aeefd7..858ab65 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaSuperAdapterLinker.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaSuperAdapterLinker.java
@@ -37,7 +37,6 @@
import jdk.internal.dynalink.linker.LinkRequest;
import jdk.internal.dynalink.linker.LinkerServices;
import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.internal.dynalink.support.Lookup;
import jdk.nashorn.internal.runtime.ScriptRuntime;
@@ -78,7 +77,7 @@
}
final CallSiteDescriptor descriptor = linkRequest.getCallSiteDescriptor();
- if(!CallSiteDescriptorFactory.tokenizeOperators(descriptor).contains(GET_METHOD)) {
+ if(!descriptor.tokenizeOperators().contains(GET_METHOD)) {
// We only handle getMethod
return null;
}
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornCallSiteDescriptor.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornCallSiteDescriptor.java
index cc654dc..a2e85cf 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornCallSiteDescriptor.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornCallSiteDescriptor.java
@@ -32,7 +32,6 @@
import java.util.concurrent.ConcurrentMap;
import jdk.internal.dynalink.CallSiteDescriptor;
import jdk.internal.dynalink.support.AbstractCallSiteDescriptor;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.nashorn.internal.ir.debug.NashornTextifier;
import jdk.nashorn.internal.runtime.ScriptRuntime;
@@ -150,7 +149,7 @@
*/
public static NashornCallSiteDescriptor get(final MethodHandles.Lookup lookup, final String name,
final MethodType methodType, final int flags) {
- final String[] tokenizedName = CallSiteDescriptorFactory.tokenizeName(name);
+ final String[] tokenizedName = CallSiteDescriptor.tokenizeName(name);
assert tokenizedName.length >= 2;
assert "dyn".equals(tokenizedName[0]);
assert tokenizedName[1] != null;
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornLinker.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornLinker.java
index ddcbae1..7700cb8 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornLinker.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornLinker.java
@@ -40,6 +40,7 @@
import java.util.Queue;
import javax.script.Bindings;
import jdk.internal.dynalink.CallSiteDescriptor;
+import jdk.internal.dynalink.DynamicLinker;
import jdk.internal.dynalink.linker.ConversionComparator;
import jdk.internal.dynalink.linker.GuardedInvocation;
import jdk.internal.dynalink.linker.GuardedTypeConversion;
@@ -48,7 +49,6 @@
import jdk.internal.dynalink.linker.LinkerServices;
import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
import jdk.internal.dynalink.support.Guards;
-import jdk.internal.dynalink.support.LinkerServicesImpl;
import jdk.internal.dynalink.support.Lookup;
import jdk.nashorn.api.scripting.JSObject;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
@@ -175,7 +175,7 @@
final LinkRequest currentRequest = AccessController.doPrivileged(new PrivilegedAction<LinkRequest>() {
@Override
public LinkRequest run() {
- return LinkerServicesImpl.getCurrentLinkRequest();
+ return DynamicLinker.getCurrentLinkRequest();
}
});
return currentRequest == null ? MethodHandles.publicLookup() : currentRequest.getCallSiteDescriptor().getLookup();
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java
index 6c2f885..3e0022e 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java
@@ -35,7 +35,6 @@
import jdk.internal.dynalink.CallSiteDescriptor;
import jdk.internal.dynalink.linker.GuardedInvocation;
import jdk.internal.dynalink.linker.LinkRequest;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.internal.dynalink.support.Guards;
import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.FindProperty;
@@ -109,7 +108,7 @@
find = null;
}
- final String firstOp = CallSiteDescriptorFactory.tokenizeOperators(desc).get(0);
+ final String firstOp = desc.tokenizeOperators().get(0);
switch (firstOp) {
case "getProp":
diff --git a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java
index 10ab434..f0d3cf2 100644
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java
@@ -34,10 +34,9 @@
import jdk.internal.dynalink.linker.LinkRequest;
import jdk.internal.dynalink.linker.LinkerServices;
import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
-import jdk.internal.dynalink.support.CallSiteDescriptorFactory;
import jdk.nashorn.api.scripting.ClassFilter;
-import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.objects.Global;
+import jdk.nashorn.internal.runtime.Context;
/**
* Check java reflection permission for java reflective and java.lang.invoke access from scripts
@@ -130,7 +129,7 @@
// 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.tokenizeOperators().contains("getProp")) {
if (desc.getNameTokenCount() > CallSiteDescriptor.NAME_OPERAND &&
"static".equals(desc.getNameToken(CallSiteDescriptor.NAME_OPERAND))) {
if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) {