# HG changeset patch # User attila # Date 1445376798 -7200 # Node ID af3fea63e00814f6afc3f47127c183793f36f081 # Parent 47279b2180b4762b1219c9da233f4c2039006c89 8139761: Improve Dynalink class nomenclature and package organization Reviewed-by: hannesw, sundar diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ChainedCallSite.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ChainedCallSite.java Mon Oct 19 22:36:03 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,244 +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.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.util.Arrays; -import java.util.Iterator; -import java.util.LinkedList; -import jdk.internal.dynalink.linker.GuardedInvocation; -import jdk.internal.dynalink.support.AbstractRelinkableCallSite; -import jdk.internal.dynalink.support.Lookup; - -/** - * A relinkable call site that implements a polymorphic inline caching strategy. - * It remembers up to 8 {@link GuardedInvocation}s it was linked with, and on - * each relink request builds a cascading chain of method handles of one - * invocation falling back to the next one. The number of remembered invocations - * can be customized by overriding {@link #getMaxChainLength()} in a subclass. - * When this call site is relinked with a new invocation and the length of the - * chain is already at the maximum, it will throw away the oldest invocation. - * Invocations with invalidated switch points and ones for which their - * invalidating exception triggered are removed eagerly from the chain. The - * invocations are never reordered; the most recently linked method handle is - * always at the start of the chain and the least recently linked at its end. - * The call site can be safely relinked on more than one thread concurrently. - * Race conditions in linking are resolved by throwing away the - * {@link GuardedInvocation} produced on the losing thread without incorporating - * it into the chain, so it can lead to repeated linking for the same arguments. - */ -public class ChainedCallSite extends AbstractRelinkableCallSite { - private static final MethodHandle PRUNE_CATCHES; - private static final MethodHandle PRUNE_SWITCHPOINTS; - static { - final MethodHandle PRUNE = Lookup.findOwnSpecial(MethodHandles.lookup(), "prune", MethodHandle.class, - MethodHandle.class, boolean.class); - PRUNE_CATCHES = MethodHandles.insertArguments(PRUNE, 2, true); - PRUNE_SWITCHPOINTS = MethodHandles.insertArguments(PRUNE, 2, false); - } - - /** - * Contains the invocations currently linked into this call site's target. They are used when we are - * relinking to rebuild the guardWithTest chain. Valid values for this field are: {@code null} if there's - * no linked invocations, or an instance of {@link GuardedInvocation} if there is exactly one previous - * invocation, or an instance of {@code GuardedInvocation[]} if there is more than one previous - * invocation. - */ - private Object invocations; - - /** - * Creates a new chained call site. - * @param descriptor the descriptor for the call site. - */ - public ChainedCallSite(final CallSiteDescriptor descriptor) { - super(descriptor); - } - - /** - * The maximum number of method handles in the chain. Defaults to 8. You can - * override it in a subclass if you need to change the value. - * @return the maximum number of method handles in the chain. The return - * value is checked, and if your override returns a value less than 1, a - * {@link RuntimeException} will be thrown. - */ - protected int getMaxChainLength() { - return 8; - } - - @Override - public void relink(final GuardedInvocation guardedInvocation, final MethodHandle relinkAndInvoke) { - relinkInternal(guardedInvocation, relinkAndInvoke, false, false); - } - - @Override - public void resetAndRelink(final GuardedInvocation guardedInvocation, final MethodHandle relinkAndInvoke) { - relinkInternal(guardedInvocation, relinkAndInvoke, true, false); - } - - private MethodHandle relinkInternal(final GuardedInvocation invocation, final MethodHandle relink, final boolean reset, final boolean removeCatches) { - final Object currentInvocations = invocations; - final LinkedList newInvocations; - if (currentInvocations == null || reset) { - newInvocations = new LinkedList<>(); - } else if (currentInvocations instanceof GuardedInvocation) { - newInvocations = new LinkedList<>(); - newInvocations.add((GuardedInvocation)currentInvocations); - } else if (currentInvocations instanceof GuardedInvocation[]) { - newInvocations = new LinkedList<>(Arrays.asList(((GuardedInvocation[])currentInvocations))); - } else { - throw new AssertionError(); - } - - // First, prune the chain of invalidated switchpoints, we always do this - // We also remove any catches if the remove catches flag is set - for(final Iterator it = newInvocations.iterator(); it.hasNext();) { - final GuardedInvocation inv = it.next(); - if(inv.hasBeenInvalidated() || (removeCatches && inv.getException() != null)) { - it.remove(); - } - } - - // prune() is allowed to invoke this method with invocation == null meaning we're just pruning the chain and not - // adding any new invocations to it. - if(invocation != null) { - // Remove oldest entry if we're at max length - if(newInvocations.size() == checkMaxChainLength(getMaxChainLength())) { - newInvocations.removeFirst(); - } - newInvocations.addLast(invocation); - } - - // prune-and-invoke is used as the fallback for invalidated switchpoints. If a switchpoint gets invalidated, we - // rebuild the chain and get rid of all invalidated switchpoints instead of letting them linger. - final MethodHandle pruneAndInvokeSwitchPoints = makePruneAndInvokeMethod(relink, PRUNE_SWITCHPOINTS); - final MethodHandle pruneAndInvokeCatches = makePruneAndInvokeMethod(relink, PRUNE_CATCHES); - - // Fold the new chain - MethodHandle target = relink; - for(final GuardedInvocation inv: newInvocations) { - target = inv.compose(target, pruneAndInvokeSwitchPoints, pruneAndInvokeCatches); - } - - switch (newInvocations.size()) { - case 0: - invocations = null; - break; - case 1: - invocations = newInvocations.getFirst(); - break; - default: - invocations = newInvocations.toArray(new GuardedInvocation[newInvocations.size()]); - } - setTarget(target); - 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. - * @param relinkAndInvoke the ultimate fallback for the chain passed from the dynamic linker. - * @return a method handle for prune-and-invoke - */ - private MethodHandle makePruneAndInvokeMethod(final MethodHandle relinkAndInvoke, final MethodHandle prune) { - // Bind prune to (this, relink) - final MethodHandle boundPrune = MethodHandles.insertArguments(prune, 0, this, relinkAndInvoke); - // Make it ignore all incoming arguments - final MethodHandle ignoreArgsPrune = MethodHandles.dropArguments(boundPrune, 0, type().parameterList()); - // Invoke prune, then invoke the call site target with original arguments - return MethodHandles.foldArguments(MethodHandles.exactInvoker(type()), ignoreArgsPrune); - } - - @SuppressWarnings("unused") - private MethodHandle prune(final MethodHandle relink, final boolean catches) { - return relinkInternal(null, relink, false, catches); - } -} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ClassMap.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ClassMap.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ClassMap.java Tue Oct 20 23:33:18 2015 +0200 @@ -91,7 +91,7 @@ import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import jdk.internal.dynalink.support.Guards; +import jdk.internal.dynalink.linker.support.Guards; /** * A dual map that can either strongly or weakly reference a given class depending on whether the class is visible from diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -89,12 +89,15 @@ import java.lang.invoke.MutableCallSite; import java.util.Objects; import jdk.internal.dynalink.linker.GuardedInvocation; +import jdk.internal.dynalink.linker.GuardedInvocationTransformer; import jdk.internal.dynalink.linker.GuardingDynamicLinker; import jdk.internal.dynalink.linker.LinkRequest; import jdk.internal.dynalink.linker.LinkerServices; -import jdk.internal.dynalink.support.Lookup; +import jdk.internal.dynalink.linker.support.Lookup; +import jdk.internal.dynalink.linker.support.SimpleLinkRequest; +import jdk.internal.dynalink.support.ChainedCallSite; import jdk.internal.dynalink.support.SimpleCallSiteDescriptor; -import jdk.internal.dynalink.support.SimpleLinkRequest; +import jdk.internal.dynalink.support.SimpleRelinkableCallSite; /** * The linker for {@link RelinkableCallSite} objects. Users of Dynalink have to @@ -115,7 +118,7 @@ * } * * public static CallSite bootstrap(MethodHandles.Lookup lookup, String name, MethodType type) { - * return dynamicLinker.link(new MonomorphicCallSite(new SimpleCallSiteDescriptor(lookup, name, type))); + * return dynamicLinker.link(new SimpleRelinkableCallSite(new SimpleCallSiteDescriptor(lookup, name, type))); * } * } * @@ -130,7 +133,7 @@ * on the factory. * *
  • The performance of the programs can depend on your choice of the class to - * represent call sites. The above example used {@link MonomorphicCallSite}, but + * represent call sites. The above example used {@link SimpleRelinkableCallSite}, but * you might want to use {@link ChainedCallSite} instead. You'll need to * experiment and decide what fits your language runtime the best. You can * subclass either of these or roll your own if you need to.
  • @@ -154,7 +157,7 @@ private static final String INVOKE_PACKAGE_PREFIX = "java.lang.invoke."; private final LinkerServices linkerServices; - private final GuardedInvocationFilter prelinkFilter; + private final GuardedInvocationTransformer prelinkTransformer; private final boolean syncOnRelink; private final int unstableRelinkThreshold; @@ -162,17 +165,17 @@ * Creates a new dynamic linker. * * @param linkerServices the linkerServices used by the linker, created by the factory. - * @param prelinkFilter see {@link DynamicLinkerFactory#setPrelinkFilter(GuardedInvocationFilter)} + * @param prelinkTransformer see {@link DynamicLinkerFactory#setPrelinkTransformer(GuardedInvocationTransformer)} * @param syncOnRelink see {@link DynamicLinkerFactory#setSyncOnRelink(boolean)} * @param unstableRelinkThreshold see {@link DynamicLinkerFactory#setUnstableRelinkThreshold(int)} */ - DynamicLinker(final LinkerServices linkerServices, final GuardedInvocationFilter prelinkFilter, + DynamicLinker(final LinkerServices linkerServices, final GuardedInvocationTransformer prelinkTransformer, final boolean syncOnRelink, final int unstableRelinkThreshold) { if(unstableRelinkThreshold < 0) { throw new IllegalArgumentException("unstableRelinkThreshold < 0"); } this.linkerServices = linkerServices; - this.prelinkFilter = prelinkFilter; + this.prelinkTransformer = prelinkTransformer; this.syncOnRelink = syncOnRelink; this.unstableRelinkThreshold = unstableRelinkThreshold; } @@ -246,9 +249,9 @@ throw new NoSuchDynamicMethodException(callSiteDescriptor.toString()); } - // Make sure we filter the invocation before linking it into the call site. This is typically used to match the + // Make sure we transform the invocation before linking it into the call site. This is typically used to match the // return type of the invocation to the call site. - guardedInvocation = prelinkFilter.filter(guardedInvocation, linkRequest, linkerServices); + guardedInvocation = prelinkTransformer.filter(guardedInvocation, linkRequest, linkerServices); Objects.requireNonNull(guardedInvocation); int newRelinkCount = relinkCount; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java Tue Oct 20 23:33:18 2015 +0200 @@ -83,6 +83,8 @@ package jdk.internal.dynalink; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodType; import java.lang.invoke.MutableCallSite; import java.security.AccessController; import java.security.PrivilegedAction; @@ -96,15 +98,16 @@ import java.util.Set; import jdk.internal.dynalink.beans.BeansLinker; import jdk.internal.dynalink.linker.GuardedInvocation; +import jdk.internal.dynalink.linker.GuardedInvocationTransformer; 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.CompositeGuardingDynamicLinker; -import jdk.internal.dynalink.support.CompositeTypeBasedGuardingDynamicLinker; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.CompositeGuardingDynamicLinker; +import jdk.internal.dynalink.linker.support.CompositeTypeBasedGuardingDynamicLinker; +import jdk.internal.dynalink.linker.support.TypeUtilities; /** * A factory class for creating {@link DynamicLinker} objects. The usual dynamic @@ -130,7 +133,7 @@ private List fallbackLinkers; private boolean syncOnRelink = false; private int unstableRelinkThreshold = DEFAULT_UNSTABLE_RELINK_THRESHOLD; - private GuardedInvocationFilter prelinkFilter; + private GuardedInvocationTransformer prelinkTransformer; private MethodTypeConversionStrategy autoConversionStrategy; private MethodHandleTransformer internalObjectsFilter; @@ -245,29 +248,29 @@ } /** - * Set the pre-link filter. This is a {@link GuardedInvocationFilter} that will get the final chance to modify the + * Set the pre-link transformer. This is a {@link GuardedInvocationTransformer} 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, 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. + * When not set explicitly, a default pre-link transformer will be used that simply calls + * {@link GuardedInvocation#asType(LinkerServices, MethodType)} + * @param prelinkTransformer the pre-link transformer for the dynamic linker. */ - public void setPrelinkFilter(final GuardedInvocationFilter prelinkFilter) { - this.prelinkFilter = prelinkFilter; + public void setPrelinkTransformer(final GuardedInvocationTransformer prelinkTransformer) { + this.prelinkTransformer = prelinkTransformer; } /** * Sets an object representing the conversion strategy for automatic type conversions. After - * {@link TypeConverterFactory#asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)} has + * {@link TypeConverterFactory#asType(MethodHandle, MethodType)} has * applied all custom conversions to a method handle, it still needs to effect * {@link TypeUtilities#isMethodInvocationConvertible(Class, Class) method invocation conversions} that * can usually be automatically applied as per - * {@link java.lang.invoke.MethodHandle#asType(java.lang.invoke.MethodType)}. + * {@link java.lang.invoke.MethodHandle#asType(MethodType)}. * However, sometimes language runtimes will want to customize even those conversions for their own call * sites. A typical example is allowing unboxing of null return values, which is by default prohibited by * ordinary {@code MethodHandles.asType}. In this case, a language runtime can install its own custom * automatic conversion strategy, that can deal with null values. Note that when the strategy's - * {@link MethodTypeConversionStrategy#asType(java.lang.invoke.MethodHandle, java.lang.invoke.MethodType)} + * {@link MethodTypeConversionStrategy#asType(MethodHandle, MethodType)} * is invoked, the custom language conversions will already have been applied to the method handle, so by * design the difference between the handle's current method type and the desired final type will always * only be ones that can be subjected to method invocation conversions. The strategy also doesn't need to @@ -290,7 +293,7 @@ /** * Creates a new dynamic linker consisting of all the prioritized, autodiscovered, and fallback linkers as well as - * the pre-link filter. + * the pre-link transformer. * * @return the new dynamic Linker */ @@ -355,12 +358,12 @@ } } - if(prelinkFilter == null) { - prelinkFilter = (inv, request, linkerServices) -> inv.asType(linkerServices, request.getCallSiteDescriptor().getMethodType()); + if(prelinkTransformer == null) { + prelinkTransformer = (inv, request, linkerServices) -> inv.asType(linkerServices, request.getCallSiteDescriptor().getMethodType()); } return new DynamicLinker(new LinkerServicesImpl(new TypeConverterFactory(typeConverters, - autoConversionStrategy), composite, internalObjectsFilter), prelinkFilter, + autoConversionStrategy), composite, internalObjectsFilter), prelinkTransformer, syncOnRelink, unstableRelinkThreshold); } diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/GuardedInvocationFilter.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/GuardedInvocationFilter.java Mon Oct 19 22:36:03 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +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 jdk.internal.dynalink.linker.GuardedInvocation; -import jdk.internal.dynalink.linker.LinkRequest; -import jdk.internal.dynalink.linker.LinkerServices; - -/** - * 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 either the same or potentially - * different guarded invocation. - * @param inv the original guarded invocation. - * @param linkRequest the link request for which the invocation was - * generated (usually by some linker). - * @param linkerServices the linker services that can be used during - * creation of a new invocation. - * @return either the passed guarded invocation or a different one, with - * the difference usually determined based on information in the link - * request and the differing invocation created with the assistance of the - * linker services. Whether or not {@code null} is an accepted return value - * is dependent on the user of the filter. - * @throws NullPointerException is allowed if any of the passed arguments - * is null. - */ - public GuardedInvocation filter(GuardedInvocation inv, LinkRequest linkRequest, LinkerServices linkerServices); -} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/MonomorphicCallSite.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/MonomorphicCallSite.java Mon Oct 19 22:36:03 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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; - -import java.lang.invoke.MethodHandle; -import jdk.internal.dynalink.linker.GuardedInvocation; -import jdk.internal.dynalink.support.AbstractRelinkableCallSite; - -/** - * A relinkable call site that implements monomorphic inline caching strategy, - * only being linked to a single {@link GuardedInvocation}. If that invocation - * is invalidated, it will throw it away and ask its associated - * {@link DynamicLinker} to relink it. - */ -public class MonomorphicCallSite extends AbstractRelinkableCallSite { - /** - * Creates a new call site with monomorphic inline caching strategy. - * @param descriptor the descriptor for this call site - */ - public MonomorphicCallSite(final CallSiteDescriptor descriptor) { - super(descriptor); - } - - @Override - public void relink(final GuardedInvocation guardedInvocation, final MethodHandle relinkAndInvoke) { - setTarget(guardedInvocation.compose(relinkAndInvoke)); - } - - @Override - public void resetAndRelink(final GuardedInvocation guardedInvocation, final MethodHandle relinkAndInvoke) { - relink(guardedInvocation, relinkAndInvoke); - } -} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/RelinkableCallSite.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/RelinkableCallSite.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/RelinkableCallSite.java Tue Oct 20 23:33:18 2015 +0200 @@ -86,12 +86,14 @@ import java.lang.invoke.CallSite; import java.lang.invoke.MethodHandle; import jdk.internal.dynalink.linker.GuardedInvocation; +import jdk.internal.dynalink.support.ChainedCallSite; +import jdk.internal.dynalink.support.SimpleRelinkableCallSite; /** * Interface for call sites managed by a {@link DynamicLinker}. Users of * Dynalink must use subclasses of {@link CallSite} that also implement this * interface as their call site implementations. There is a readily usable - * {@link MonomorphicCallSite} subclass that implements monomorphic inline + * {@link SimpleRelinkableCallSite} subclass that implements monomorphic inline * caching strategy as well as {@link ChainedCallSite} that implements a * polymorphic inline caching strategy and retains a chain of previously linked * method handles. A relinkable call site will be managed by a diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/TypeConverterFactory.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/TypeConverterFactory.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/TypeConverterFactory.java Tue Oct 20 23:33:18 2015 +0200 @@ -99,7 +99,7 @@ import jdk.internal.dynalink.linker.GuardingTypeConverterFactory; import jdk.internal.dynalink.linker.LinkerServices; import jdk.internal.dynalink.linker.MethodTypeConversionStrategy; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.TypeUtilities; /** * A factory for type converters. This class is the main implementation behind the diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/AbstractJavaLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/AbstractJavaLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/AbstractJavaLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -103,9 +103,9 @@ import jdk.internal.dynalink.linker.GuardingDynamicLinker; import jdk.internal.dynalink.linker.LinkRequest; import jdk.internal.dynalink.linker.LinkerServices; -import jdk.internal.dynalink.support.Guards; -import jdk.internal.dynalink.support.Lookup; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.Guards; +import jdk.internal.dynalink.linker.support.Lookup; +import jdk.internal.dynalink.linker.support.TypeUtilities; import sun.reflect.CallerSensitive; /** diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ApplicableOverloadedMethods.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ApplicableOverloadedMethods.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ApplicableOverloadedMethods.java Tue Oct 20 23:33:18 2015 +0200 @@ -86,7 +86,7 @@ import java.lang.invoke.MethodType; import java.util.LinkedList; import java.util.List; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.TypeUtilities; /** * Represents overloaded methods applicable to a specific call site signature. diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/BeanLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/BeanLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/BeanLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -95,9 +95,9 @@ import jdk.internal.dynalink.linker.GuardedInvocation; import jdk.internal.dynalink.linker.LinkerServices; import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker; -import jdk.internal.dynalink.support.Guards; -import jdk.internal.dynalink.support.Lookup; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.Guards; +import jdk.internal.dynalink.linker.support.Lookup; +import jdk.internal.dynalink.linker.support.TypeUtilities; /** * A class that provides linking capabilities for a single POJO class. Normally not used directly, but managed by diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/CallerSensitiveDynamicMethod.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/CallerSensitiveDynamicMethod.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/CallerSensitiveDynamicMethod.java Tue Oct 20 23:33:18 2015 +0200 @@ -94,7 +94,7 @@ import java.security.AccessController; import java.security.PrivilegedAction; import jdk.internal.dynalink.CallSiteDescriptor; -import jdk.internal.dynalink.support.Lookup; +import jdk.internal.dynalink.linker.support.Lookup; /** * A dynamic method bound to exactly one Java method or constructor that is caller sensitive. Since the target method is diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ClassLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ClassLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ClassLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -87,7 +87,7 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import jdk.internal.dynalink.beans.GuardedInvocationComponent.ValidationType; -import jdk.internal.dynalink.support.Lookup; +import jdk.internal.dynalink.linker.support.Lookup; /** * A linker for java.lang.Class objects. Provides a synthetic property "static" that allows access to static fields and diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ClassString.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ClassString.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ClassString.java Tue Oct 20 23:33:18 2015 +0200 @@ -91,8 +91,8 @@ import java.util.LinkedList; import java.util.List; import jdk.internal.dynalink.linker.LinkerServices; -import jdk.internal.dynalink.support.Guards; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.Guards; +import jdk.internal.dynalink.linker.support.TypeUtilities; /** * Represents a sequence of {@link Class} objects, useful for representing method signatures. Provides value diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/DynamicMethodLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/DynamicMethodLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/DynamicMethodLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -90,7 +90,7 @@ import jdk.internal.dynalink.linker.LinkRequest; import jdk.internal.dynalink.linker.LinkerServices; import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker; -import jdk.internal.dynalink.support.Guards; +import jdk.internal.dynalink.linker.support.Guards; /** * Simple linker that implements the "dyn:call" operation for {@link DynamicMethod} objects - the objects returned by diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/FacetIntrospector.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/FacetIntrospector.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/FacetIntrospector.java Tue Oct 20 23:33:18 2015 +0200 @@ -92,7 +92,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Map; -import jdk.internal.dynalink.support.Lookup; +import jdk.internal.dynalink.linker.support.Lookup; /** * Base for classes that expose class field and method information to an {@link AbstractJavaLinker}. There are diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/MaximallySpecific.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/MaximallySpecific.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/MaximallySpecific.java Tue Oct 20 23:33:18 2015 +0200 @@ -90,7 +90,7 @@ import java.util.List; import jdk.internal.dynalink.linker.ConversionComparator.Comparison; import jdk.internal.dynalink.linker.LinkerServices; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.TypeUtilities; /** * Utility class that encapsulates the algorithm for choosing the maximally specific methods. diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/OverloadedDynamicMethod.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/OverloadedDynamicMethod.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/OverloadedDynamicMethod.java Tue Oct 20 23:33:18 2015 +0200 @@ -99,7 +99,7 @@ import jdk.internal.dynalink.CallSiteDescriptor; import jdk.internal.dynalink.beans.ApplicableOverloadedMethods.ApplicabilityTest; import jdk.internal.dynalink.linker.LinkerServices; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.TypeUtilities; /** * Represents a group of {@link SingleDynamicMethod} objects that represents all overloads of a particular name (or all diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/OverloadedMethod.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/OverloadedMethod.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/OverloadedMethod.java Tue Oct 20 23:33:18 2015 +0200 @@ -92,8 +92,8 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import jdk.internal.dynalink.linker.LinkerServices; -import jdk.internal.dynalink.support.Lookup; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.Lookup; +import jdk.internal.dynalink.linker.support.TypeUtilities; /** * Represents a subset of overloaded methods for a certain method name on a certain class. It can be either a fixarg or diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/SingleDynamicMethod.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/SingleDynamicMethod.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/SingleDynamicMethod.java Tue Oct 20 23:33:18 2015 +0200 @@ -90,8 +90,8 @@ import java.util.StringTokenizer; import jdk.internal.dynalink.CallSiteDescriptor; import jdk.internal.dynalink.linker.LinkerServices; -import jdk.internal.dynalink.support.Guards; -import jdk.internal.dynalink.support.Lookup; +import jdk.internal.dynalink.linker.support.Guards; +import jdk.internal.dynalink.linker.support.Lookup; /** * Base class for dynamic methods that dispatch to a single target Java method or constructor. Handles adaptation of the diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/StaticClassLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/StaticClassLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/StaticClassLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -95,7 +95,7 @@ import jdk.internal.dynalink.linker.LinkRequest; import jdk.internal.dynalink.linker.LinkerServices; import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker; -import jdk.internal.dynalink.support.Lookup; +import jdk.internal.dynalink.linker.support.Lookup; /** * Provides a linker for the {@link StaticClass} objects. diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/GuardedInvocation.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/GuardedInvocation.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/GuardedInvocation.java Tue Oct 20 23:33:18 2015 +0200 @@ -91,7 +91,7 @@ import java.util.Objects; import java.util.function.Supplier; import jdk.internal.dynalink.CallSiteDescriptor; -import jdk.internal.dynalink.support.Guards; +import jdk.internal.dynalink.linker.support.Guards; /** * Represents a conditionally valid method handle. Usually produced as a return diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/GuardedInvocationTransformer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/GuardedInvocationTransformer.java Tue Oct 20 23:33:18 2015 +0200 @@ -0,0 +1,113 @@ +/* + * 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.linker; + +import jdk.internal.dynalink.DynamicLinkerFactory; + +/** + * Interface for objects that are used to transform one guarded invocation into + * another one. Typical usage is for implementing + * {@link DynamicLinkerFactory#setPrelinkTransformer(GuardedInvocationTransformer) + * pre-link transformers}. + */ +@FunctionalInterface +public interface GuardedInvocationTransformer { + /** + * Given a guarded invocation, return either the same or potentially + * different guarded invocation. + * @param inv the original guarded invocation. + * @param linkRequest the link request for which the invocation was + * generated (usually by some linker). + * @param linkerServices the linker services that can be used during + * creation of a new invocation. + * @return either the passed guarded invocation or a different one, with + * the difference usually determined based on information in the link + * request and the differing invocation created with the assistance of the + * linker services. Whether or not {@code null} is an accepted return value + * is dependent on the user of the filter. + * @throws NullPointerException is allowed if any of the passed arguments + * is null. + */ + public GuardedInvocation filter(GuardedInvocation inv, LinkRequest linkRequest, LinkerServices linkerServices); +} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/GuardingTypeConverterFactory.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/GuardingTypeConverterFactory.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/GuardingTypeConverterFactory.java Tue Oct 20 23:33:18 2015 +0200 @@ -87,7 +87,7 @@ import java.util.function.Supplier; import jdk.internal.dynalink.CallSiteDescriptor; import jdk.internal.dynalink.beans.BeansLinker; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.TypeUtilities; /** * Optional interface that can be implemented by {@link GuardingDynamicLinker} implementations to provide diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/LinkerServices.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/LinkerServices.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/LinkerServices.java Tue Oct 20 23:33:18 2015 +0200 @@ -89,7 +89,7 @@ import jdk.internal.dynalink.DynamicLinker; import jdk.internal.dynalink.DynamicLinkerFactory; import jdk.internal.dynalink.linker.ConversionComparator.Comparison; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.TypeUtilities; /** * Interface for services provided to {@link GuardingDynamicLinker} instances by the {@link DynamicLinker} that owns @@ -118,7 +118,7 @@ * Similar to {@link #asType(MethodHandle, MethodType)} except it only converts the return type of the method handle * when it can be done using a conversion that loses neither precision nor magnitude, otherwise it leaves it * unchanged. The idea is that other conversions should not be performed by individual linkers, but instead the - * {@link DynamicLinkerFactory#setPrelinkFilter(jdk.internal.dynalink.GuardedInvocationFilter) pre-link filter of + * {@link DynamicLinkerFactory#setPrelinkTransformer(GuardedInvocationTransformer) pre-link transformer of * the dynamic linker} should implement the strategy of dealing with potentially lossy return type conversions in a * manner specific to the language runtime. * diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/TypeBasedGuardingDynamicLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/TypeBasedGuardingDynamicLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/TypeBasedGuardingDynamicLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -83,7 +83,7 @@ package jdk.internal.dynalink.linker; -import jdk.internal.dynalink.support.CompositeTypeBasedGuardingDynamicLinker; +import jdk.internal.dynalink.linker.support.CompositeTypeBasedGuardingDynamicLinker; /** * A guarding dynamic linker that can determine whether it can link the call site solely based on the type of the first diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/CompositeGuardingDynamicLinker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/CompositeGuardingDynamicLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -0,0 +1,142 @@ +/* + * 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.linker.support; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import jdk.internal.dynalink.linker.GuardedInvocation; +import jdk.internal.dynalink.linker.GuardingDynamicLinker; +import jdk.internal.dynalink.linker.LinkRequest; +import jdk.internal.dynalink.linker.LinkerServices; + +/** + * A {@link GuardingDynamicLinker} that delegates sequentially to a list of + * other guarding dynamic linkers in its + * {@link #getGuardedInvocation(LinkRequest, LinkerServices)}. + */ +public class CompositeGuardingDynamicLinker implements GuardingDynamicLinker, Serializable { + + private static final long serialVersionUID = 1L; + + private final GuardingDynamicLinker[] linkers; + + /** + * Creates a new composite linker. + * + * @param linkers a list of component linkers. + * @throws NullPointerException if {@code linkers} or any of its elements + * are null. + */ + public CompositeGuardingDynamicLinker(final Iterable linkers) { + final List l = new LinkedList<>(); + for(final GuardingDynamicLinker linker: linkers) { + l.add(Objects.requireNonNull(linker)); + } + this.linkers = l.toArray(new GuardingDynamicLinker[l.size()]); + } + + /** + * Delegates the call to its component linkers. The first non-null value + * returned from a component linker is returned. If no component linker + * returns a non-null invocation, null is returned. + * @param linkRequest the object describing the request for linking a + * particular invocation + * @param linkerServices linker services + * @return the first non-null return value from a component linker, or null + * if none of the components returned a non-null. + */ + @Override + public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) + throws Exception { + for(final GuardingDynamicLinker linker: linkers) { + final GuardedInvocation invocation = linker.getGuardedInvocation(linkRequest, linkerServices); + if(invocation != null) { + return invocation; + } + } + return null; + } +} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/CompositeTypeBasedGuardingDynamicLinker.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/CompositeTypeBasedGuardingDynamicLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -0,0 +1,239 @@ +/* + * 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.linker.support; + +import java.io.Serializable; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import jdk.internal.dynalink.linker.GuardedInvocation; +import jdk.internal.dynalink.linker.GuardingDynamicLinker; +import jdk.internal.dynalink.linker.LinkRequest; +import jdk.internal.dynalink.linker.LinkerServices; +import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker; + +/** + * A composite type-based guarding dynamic linker. When a receiver of a not yet + * seen class is encountered, all linkers are queried sequentially on their + * {@link TypeBasedGuardingDynamicLinker#canLinkType(Class)} method. The linkers + * returning true are then bound to the class, and next time a receiver of same + * type is encountered, the linking is delegated to those linkers only, speeding + * up dispatch. + */ +public class CompositeTypeBasedGuardingDynamicLinker implements TypeBasedGuardingDynamicLinker, Serializable { + private static final long serialVersionUID = 1L; + + // Using a separate static class instance so there's no strong reference from the class value back to the composite + // linker. + private static class ClassToLinker extends ClassValue> { + private static final List NO_LINKER = Collections.emptyList(); + private final TypeBasedGuardingDynamicLinker[] linkers; + private final List[] singletonLinkers; + + @SuppressWarnings({"unchecked", "rawtypes"}) + ClassToLinker(final TypeBasedGuardingDynamicLinker[] linkers) { + this.linkers = linkers; + singletonLinkers = new List[linkers.length]; + for(int i = 0; i < linkers.length; ++i) { + singletonLinkers[i] = Collections.singletonList(linkers[i]); + } + } + + @SuppressWarnings("fallthrough") + @Override + protected List computeValue(final Class clazz) { + List list = NO_LINKER; + for(int i = 0; i < linkers.length; ++i) { + final TypeBasedGuardingDynamicLinker linker = linkers[i]; + if(linker.canLinkType(clazz)) { + switch(list.size()) { + case 0: { + list = singletonLinkers[i]; + break; + } + case 1: { + list = new LinkedList<>(list); + } + default: { + list.add(linker); + } + } + } + } + return list; + } + } + + private final ClassValue> classToLinker; + + /** + * Creates a new composite type-based linker. + * + * @param linkers the component linkers + * @throws NullPointerException if {@code linkers} or any of its elements + * are null. + */ + public CompositeTypeBasedGuardingDynamicLinker(final Iterable linkers) { + final List l = new LinkedList<>(); + for(final TypeBasedGuardingDynamicLinker linker: linkers) { + l.add(Objects.requireNonNull(linker)); + } + this.classToLinker = new ClassToLinker(l.toArray(new TypeBasedGuardingDynamicLinker[l.size()])); + } + + /** + * Returns true if any of the composite linkers return true from + * {@link TypeBasedGuardingDynamicLinker#canLinkType(Class)} for the type. + * @param type the type to link + * @return true if any of the composite linkers can link calls for the + * receiver type, false otherwise. + */ + @Override + public boolean canLinkType(final Class type) { + return !classToLinker.get(type).isEmpty(); + } + + @Override + public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) + throws Exception { + final Object obj = linkRequest.getReceiver(); + if(obj == null) { + return null; + } + for(final TypeBasedGuardingDynamicLinker linker: classToLinker.get(obj.getClass())) { + final GuardedInvocation invocation = linker.getGuardedInvocation(linkRequest, linkerServices); + if(invocation != null) { + return invocation; + } + } + return null; + } + + /** + * Optimizes a list of type-based linkers. If a group of adjacent linkers in + * the list all implement {@link TypeBasedGuardingDynamicLinker}, they will + * be replaced with a single instance of + * {@link CompositeTypeBasedGuardingDynamicLinker} that contains them. + * + * @param linkers the list of linkers to optimize + * @return the optimized list + * @throws NullPointerException if {@code linkers} or any of its elements + * are null. + */ + public static List optimize(final Iterable linkers) { + final List llinkers = new LinkedList<>(); + final List tblinkers = new LinkedList<>(); + for(final GuardingDynamicLinker linker: linkers) { + Objects.requireNonNull(linker); + if(linker instanceof TypeBasedGuardingDynamicLinker) { + tblinkers.add((TypeBasedGuardingDynamicLinker)linker); + } else { + addTypeBased(llinkers, tblinkers); + llinkers.add(linker); + } + } + addTypeBased(llinkers, tblinkers); + return llinkers; + } + + private static void addTypeBased(final List llinkers, + final List tblinkers) { + switch(tblinkers.size()) { + case 0: { + break; + } + case 1: { + llinkers.addAll(tblinkers); + tblinkers.clear(); + break; + } + default: { + llinkers.add(new CompositeTypeBasedGuardingDynamicLinker(tblinkers)); + tblinkers.clear(); + break; + } + } + } +} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/DefaultInternalObjectFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/DefaultInternalObjectFilter.java Tue Oct 20 23:33:18 2015 +0200 @@ -0,0 +1,185 @@ +/* + * 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 + * 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-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 + 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.linker.support; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import jdk.internal.dynalink.DynamicLinkerFactory; +import jdk.internal.dynalink.linker.MethodHandleTransformer; + +/** + * Default implementation for a + * {@link DynamicLinkerFactory#setInternalObjectsFilter(MethodHandleTransformer)} + * that delegates to a pair of filtering method handles. Given a method handle + * of {@code Object(Object)} type for filtering parameter and another one of the + * same type for filtering return values, applies them to passed method handles, + * on those parameter types and/or return value types that are declared to be + * {@link Object}. Also handles {@link MethodHandle#isVarargsCollector() method + * handles that support variable arity calls} with a last {@code Object[]} + * parameter. + */ +public class DefaultInternalObjectFilter implements MethodHandleTransformer { + private static final MethodHandle FILTER_VARARGS = new Lookup(MethodHandles.lookup()).findStatic( + DefaultInternalObjectFilter.class, "filterVarArgs", MethodType.methodType(Object[].class, MethodHandle.class, Object[].class)); + + private final MethodHandle parameterFilter; + private final MethodHandle returnFilter; + private final MethodHandle varArgFilter; + + /** + * Creates a new filter. + * @param parameterFilter the filter for method parameters. Must be of type + * {@code Object(Object)}, or {@code null}. + * @param returnFilter the filter for return values. Must be of type + * {@code Object(Object)}, or {@code null}. + * @throws IllegalArgumentException if one or both filters are not of the + * expected type. + */ + public DefaultInternalObjectFilter(final MethodHandle parameterFilter, final MethodHandle returnFilter) { + this.parameterFilter = checkHandle(parameterFilter, "parameterFilter"); + this.returnFilter = checkHandle(returnFilter, "returnFilter"); + this.varArgFilter = parameterFilter == null ? null : FILTER_VARARGS.bindTo(parameterFilter); + } + + @Override + public MethodHandle transform(final MethodHandle target) { + assert target != null; + MethodHandle[] filters = null; + final MethodType type = target.type(); + final boolean isVarArg = target.isVarargsCollector(); + final int paramCount = type.parameterCount(); + final MethodHandle paramsFiltered; + // Filter parameters + if (parameterFilter != null) { + int firstFilter = -1; + // Ignore receiver, start from argument 1 + for(int i = 1; i < paramCount; ++i) { + final Class paramType = type.parameterType(i); + final boolean filterVarArg = isVarArg && i == paramCount - 1 && paramType == Object[].class; + if (filterVarArg || paramType == Object.class) { + if (filters == null) { + firstFilter = i; + filters = new MethodHandle[paramCount - firstFilter]; + } + filters[i - firstFilter] = filterVarArg ? varArgFilter : parameterFilter; + } + } + paramsFiltered = filters != null ? MethodHandles.filterArguments(target, firstFilter, filters) : target; + } else { + paramsFiltered = target; + } + // Filter return value if needed + final MethodHandle returnFiltered = returnFilter != null && type.returnType() == Object.class ? MethodHandles.filterReturnValue(paramsFiltered, returnFilter) : paramsFiltered; + // Preserve varargs collector state + return isVarArg && !returnFiltered.isVarargsCollector() ? returnFiltered.asVarargsCollector(type.parameterType(paramCount - 1)) : returnFiltered; + + } + + private static MethodHandle checkHandle(final MethodHandle handle, final String handleKind) { + if (handle != null) { + final MethodType objectObjectType = MethodType.methodType(Object.class, Object.class); + if (!handle.type().equals(objectObjectType)) { + throw new IllegalArgumentException("Method type for " + handleKind + " must be " + objectObjectType); + } + } + return handle; + } + + @SuppressWarnings("unused") + private static Object[] filterVarArgs(final MethodHandle parameterFilter, final Object[] args) throws Throwable { + Object[] newArgs = null; + for(int i = 0; i < args.length; ++i) { + final Object arg = args[i]; + final Object newArg = parameterFilter.invokeExact(arg); + if (arg != newArg) { + if (newArgs == null) { + newArgs = args.clone(); + } + newArgs[i] = newArg; + } + } + return newArgs == null ? args : newArgs; + } +} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/Guards.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/Guards.java Tue Oct 20 23:33:18 2015 +0200 @@ -0,0 +1,359 @@ +/* + * 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.linker.support; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.util.logging.Level; +import java.util.logging.Logger; +import jdk.internal.dynalink.DynamicLinker; +import jdk.internal.dynalink.linker.LinkerServices; + +/** + * Utility methods for creating typical guards. + */ +public final class Guards { + private static final Logger LOG = Logger + .getLogger(Guards.class.getName(), "jdk.internal.dynalink.support.messages"); + + private Guards() { + } + + /** + * Creates a guard method handle with arguments of a specified type, but with boolean return value. When invoked, it + * returns true if the first argument is of the specified class (exactly of it, not a subclass). The rest of the + * arguments will be ignored. + * + * @param clazz the class of the first argument to test for + * @param type the method type + * @return a method handle testing whether its first argument is of the specified class. + */ + @SuppressWarnings("boxing") + public static MethodHandle isOfClass(final Class clazz, final MethodType type) { + final Class declaredType = type.parameterType(0); + if(clazz == declaredType) { + LOG.log(Level.WARNING, "isOfClassGuardAlwaysTrue", new Object[] { clazz.getName(), 0, type, DynamicLinker.getLinkedCallSiteLocation() }); + return constantTrue(type); + } + if(!declaredType.isAssignableFrom(clazz)) { + LOG.log(Level.WARNING, "isOfClassGuardAlwaysFalse", new Object[] { clazz.getName(), 0, type, DynamicLinker.getLinkedCallSiteLocation() }); + return constantFalse(type); + } + return getClassBoundArgumentTest(IS_OF_CLASS, clazz, 0, type); + } + + /** + * Creates a method handle with arguments of a specified type, but with boolean return value. When invoked, it + * returns true if the first argument is instance of the specified class or its subclass). The rest of the arguments + * will be ignored. + * + * @param clazz the class of the first argument to test for + * @param type the method type + * @return a method handle testing whether its first argument is of the specified class or subclass. + */ + public static MethodHandle isInstance(final Class clazz, final MethodType type) { + return isInstance(clazz, 0, type); + } + + /** + * Creates a method handle with arguments of a specified type, but with boolean return value. When invoked, it + * returns true if the n'th argument is instance of the specified class or its subclass). The rest of the arguments + * will be ignored. + * + * @param clazz the class of the first argument to test for + * @param pos the position on the argument list to test + * @param type the method type + * @return a method handle testing whether its first argument is of the specified class or subclass. + */ + @SuppressWarnings("boxing") + public static MethodHandle isInstance(final Class clazz, final int pos, final MethodType type) { + final Class declaredType = type.parameterType(pos); + if(clazz.isAssignableFrom(declaredType)) { + LOG.log(Level.WARNING, "isInstanceGuardAlwaysTrue", new Object[] { clazz.getName(), pos, type, DynamicLinker.getLinkedCallSiteLocation() }); + return constantTrue(type); + } + if(!declaredType.isAssignableFrom(clazz)) { + LOG.log(Level.WARNING, "isInstanceGuardAlwaysFalse", new Object[] { clazz.getName(), pos, type, DynamicLinker.getLinkedCallSiteLocation() }); + return constantFalse(type); + } + return getClassBoundArgumentTest(IS_INSTANCE, clazz, pos, type); + } + + /** + * Creates a method handle that returns true if the argument in the specified position is a Java array. + * + * @param pos the position in the argument lit + * @param type the method type of the handle + * @return a method handle that returns true if the argument in the specified position is a Java array; the rest of + * the arguments are ignored. + */ + @SuppressWarnings("boxing") + public static MethodHandle isArray(final int pos, final MethodType type) { + final Class declaredType = type.parameterType(pos); + if(declaredType.isArray()) { + LOG.log(Level.WARNING, "isArrayGuardAlwaysTrue", new Object[] { pos, type, DynamicLinker.getLinkedCallSiteLocation() }); + return constantTrue(type); + } + if(!declaredType.isAssignableFrom(Object[].class)) { + LOG.log(Level.WARNING, "isArrayGuardAlwaysFalse", new Object[] { pos, type, DynamicLinker.getLinkedCallSiteLocation() }); + return constantFalse(type); + } + return asType(IS_ARRAY, pos, type); + } + + /** + * Return true if it is safe to strongly reference a class from the referred class loader from a class associated + * with the referring class loader without risking a class loader memory leak. + * + * @param referrerLoader the referrer class loader + * @param referredLoader the referred class loader + * @return true if it is safe to strongly reference the class + */ + public static boolean canReferenceDirectly(final ClassLoader referrerLoader, final ClassLoader referredLoader) { + if(referredLoader == null) { + // Can always refer directly to a system class + return true; + } + if(referrerLoader == null) { + // System classes can't refer directly to any non-system class + return false; + } + // Otherwise, can only refer directly to classes residing in same or + // parent class loader. + + ClassLoader referrer = referrerLoader; + do { + if(referrer == referredLoader) { + return true; + } + referrer = referrer.getParent(); + } while(referrer != null); + return false; + } + + private static MethodHandle getClassBoundArgumentTest(final MethodHandle test, final Class clazz, final int pos, final MethodType type) { + // Bind the class to the first argument of the test + return asType(test.bindTo(clazz), pos, type); + } + + /** + * Takes a guard-test method handle, and adapts it to the requested type, returning a boolean. Only applies + * conversions as per {@link MethodHandle#asType(MethodType)}. + * @param test the test method handle + * @param type the type to adapt the method handle to + * @return the adapted method handle + */ + public static MethodHandle asType(final MethodHandle test, final MethodType type) { + return test.asType(getTestType(test, type)); + } + + /** + * Takes a guard-test method handle, and adapts it to the requested type, returning a boolean. Applies the passed + * {@link LinkerServices} object's {@link LinkerServices#asType(MethodHandle, MethodType)}. + * @param linkerServices the linker services to use for type conversions + * @param test the test method handle + * @param type the type to adapt the method handle to + * @return the adapted method handle + */ + public static MethodHandle asType(final LinkerServices linkerServices, final MethodHandle test, final MethodType type) { + return linkerServices.asType(test, getTestType(test, type)); + } + + private static MethodType getTestType(final MethodHandle test, final MethodType type) { + return type.dropParameterTypes(test.type().parameterCount(), + type.parameterCount()).changeReturnType(boolean.class); + } + + private static MethodHandle asType(final MethodHandle test, final int pos, final MethodType type) { + assert test != null; + assert type != null; + assert type.parameterCount() > 0; + assert pos >= 0 && pos < type.parameterCount(); + assert test.type().parameterCount() == 1; + assert test.type().returnType() == Boolean.TYPE; + return MethodHandles.permuteArguments(test.asType(test.type().changeParameterType(0, type.parameterType(pos))), + type.changeReturnType(Boolean.TYPE), new int[] { pos }); + } + + private static final MethodHandle IS_INSTANCE = Lookup.PUBLIC.findVirtual(Class.class, "isInstance", + MethodType.methodType(Boolean.TYPE, Object.class)); + + private static final MethodHandle IS_OF_CLASS; + private static final MethodHandle IS_ARRAY; + private static final MethodHandle IS_IDENTICAL; + private static final MethodHandle IS_NULL; + private static final MethodHandle IS_NOT_NULL; + + static { + final Lookup lookup = new Lookup(MethodHandles.lookup()); + + IS_OF_CLASS = lookup.findOwnStatic("isOfClass", Boolean.TYPE, Class.class, Object.class); + IS_ARRAY = lookup.findOwnStatic("isArray", Boolean.TYPE, Object.class); + IS_IDENTICAL = lookup.findOwnStatic("isIdentical", Boolean.TYPE, Object.class, Object.class); + IS_NULL = lookup.findOwnStatic("isNull", Boolean.TYPE, Object.class); + IS_NOT_NULL = lookup.findOwnStatic("isNotNull", Boolean.TYPE, Object.class); + } + + /** + * Creates a guard method that tests its only argument for being of an exact particular class. + * @param clazz the class to test for. + * @return the desired guard method. + */ + public static MethodHandle getClassGuard(final Class clazz) { + return IS_OF_CLASS.bindTo(clazz); + } + + /** + * Creates a guard method that tests its only argument for being an instance of a particular class. + * @param clazz the class to test for. + * @return the desired guard method. + */ + public static MethodHandle getInstanceOfGuard(final Class clazz) { + return IS_INSTANCE.bindTo(clazz); + } + + /** + * Creates a guard method that tests its only argument for being referentially identical to another object + * @param obj the object used as referential identity test + * @return the desired guard method. + */ + public static MethodHandle getIdentityGuard(final Object obj) { + return IS_IDENTICAL.bindTo(obj); + } + + /** + * Returns a guard that tests whether the first argument is null. + * @return a guard that tests whether the first argument is null. + */ + public static MethodHandle isNull() { + return IS_NULL; + } + + /** + * Returns a guard that tests whether the first argument is not null. + * @return a guard that tests whether the first argument is not null. + */ + public static MethodHandle isNotNull() { + return IS_NOT_NULL; + } + + @SuppressWarnings("unused") + private static boolean isNull(final Object obj) { + return obj == null; + } + + @SuppressWarnings("unused") + private static boolean isNotNull(final Object obj) { + return obj != null; + } + + @SuppressWarnings("unused") + private static boolean isArray(final Object o) { + return o != null && o.getClass().isArray(); + } + + @SuppressWarnings("unused") + private static boolean isOfClass(final Class c, final Object o) { + return o != null && o.getClass() == c; + } + + @SuppressWarnings("unused") + private static boolean isIdentical(final Object o1, final Object o2) { + return o1 == o2; + } + + private static MethodHandle constantTrue(final MethodType type) { + return constantBoolean(Boolean.TRUE, type); + } + + private static MethodHandle constantFalse(final MethodType type) { + return constantBoolean(Boolean.FALSE, type); + } + + private static MethodHandle constantBoolean(final Boolean value, final MethodType type) { + return MethodHandles.permuteArguments(MethodHandles.constant(Boolean.TYPE, value), + type.changeReturnType(Boolean.TYPE)); + } +} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/Lookup.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/Lookup.java Tue Oct 20 23:33:18 2015 +0200 @@ -0,0 +1,401 @@ +/* + * 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.linker.support; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +/** + * A wrapper around {@link java.lang.invoke.MethodHandles.Lookup} that masks + * checked exceptions. It is useful in those cases when you're looking up + * methods within your own codebase (therefore it is an error if they are not + * present). + */ +public class Lookup { + private final MethodHandles.Lookup lookup; + + /** + * Creates a new instance, bound to an instance of + * {@link java.lang.invoke.MethodHandles.Lookup}. + * + * @param lookup the {@link java.lang.invoke.MethodHandles.Lookup} it delegates to. + */ + public Lookup(final MethodHandles.Lookup lookup) { + this.lookup = lookup; + } + + /** + * A canonical Lookup object that wraps {@link MethodHandles#publicLookup()}. + */ + public static final Lookup PUBLIC = new Lookup(MethodHandles.publicLookup()); + + /** + * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)}, + * converting any encountered {@link IllegalAccessException} into an + * {@link IllegalAccessError}. + * + * @param m the method to unreflect + * @return the unreflected method handle. + * @throws IllegalAccessError if the method is inaccessible. + */ + public MethodHandle unreflect(final Method m) { + return unreflect(lookup, m); + } + + /** + * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)}, + * converting any encountered {@link IllegalAccessException} into an + * {@link IllegalAccessError}. + * + * @param lookup the lookup used to unreflect + * @param m the method to unreflect + * @return the unreflected method handle. + * @throws IllegalAccessError if the method is inaccessible. + */ + public static MethodHandle unreflect(final MethodHandles.Lookup lookup, final Method m) { + try { + return lookup.unreflect(m); + } catch(final IllegalAccessException e) { + final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect method " + m); + ee.initCause(e); + throw ee; + } + } + + /** + * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectGetter(Field)}, + * converting any encountered {@link IllegalAccessException} into an {@link IllegalAccessError}. + * + * @param f the field for which a getter is unreflected + * @return the unreflected field getter handle. + * @throws IllegalAccessError if the getter is inaccessible. + */ + public MethodHandle unreflectGetter(final Field f) { + try { + return lookup.unreflectGetter(f); + } catch(final IllegalAccessException e) { + final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect getter for field " + f); + ee.initCause(e); + throw ee; + } + } + + /** + * Performs a {@link java.lang.invoke.MethodHandles.Lookup#findGetter(Class, String, Class)}, + * converting any encountered {@link IllegalAccessException} into an + * {@link IllegalAccessError} and {@link NoSuchFieldException} into a + * {@link NoSuchFieldError}. + * + * @param refc the class declaring the field + * @param name the name of the field + * @param type the type of the field + * @return the unreflected field getter handle. + * @throws IllegalAccessError if the field is inaccessible. + * @throws NoSuchFieldError if the field does not exist. + */ + public MethodHandle findGetter(final Classrefc, final String name, final Class type) { + try { + return lookup.findGetter(refc, name, type); + } catch(final IllegalAccessException e) { + final IllegalAccessError ee = new IllegalAccessError("Failed to access getter for field " + refc.getName() + + "." + name + " of type " + type.getName()); + ee.initCause(e); + throw ee; + } catch(final NoSuchFieldException e) { + final NoSuchFieldError ee = new NoSuchFieldError("Failed to find getter for field " + refc.getName() + + "." + name + " of type " + type.getName()); + ee.initCause(e); + throw ee; + } + } + + /** + * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectSetter(Field)}, + * converting any encountered {@link IllegalAccessException} into an + * {@link IllegalAccessError}. + * + * @param f the field for which a setter is unreflected + * @return the unreflected field setter handle. + * @throws IllegalAccessError if the field is inaccessible. + * @throws NoSuchFieldError if the field does not exist. + */ + public MethodHandle unreflectSetter(final Field f) { + try { + return lookup.unreflectSetter(f); + } catch(final IllegalAccessException e) { + final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect setter for field " + f); + ee.initCause(e); + throw ee; + } + } + + /** + * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor)}, + * converting any encountered {@link IllegalAccessException} into an + * {@link IllegalAccessError}. + * + * @param c the constructor to unreflect + * @return the unreflected constructor handle. + * @throws IllegalAccessError if the constructor is inaccessible. + */ + public MethodHandle unreflectConstructor(final Constructor c) { + return unreflectConstructor(lookup, c); + } + + /** + * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor)}, + * converting any encountered {@link IllegalAccessException} into an + * {@link IllegalAccessError}. + * + * @param lookup the lookup used to unreflect + * @param c the constructor to unreflect + * @return the unreflected constructor handle. + * @throws IllegalAccessError if the constructor is inaccessible. + */ + public static MethodHandle unreflectConstructor(final MethodHandles.Lookup lookup, final Constructor c) { + try { + return lookup.unreflectConstructor(c); + } catch(final IllegalAccessException e) { + final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect constructor " + c); + ee.initCause(e); + throw ee; + } + } + + /** + * Performs a {@link java.lang.invoke.MethodHandles.Lookup#findSpecial(Class, String, MethodType, Class)} + * on the underlying lookup. Converts any encountered + * {@link IllegalAccessException} into an {@link IllegalAccessError} and + * {@link NoSuchMethodException} into a {@link NoSuchMethodError}. + * + * @param declaringClass class declaring the method + * @param name the name of the method + * @param type the type of the method + * @return a method handle for the method + * @throws IllegalAccessError if the method is inaccessible. + * @throws NoSuchMethodError if the method does not exist. + */ + public MethodHandle findSpecial(final Class declaringClass, final String name, final MethodType type) { + try { + return lookup.findSpecial(declaringClass, name, type, declaringClass); + } catch(final IllegalAccessException e) { + final IllegalAccessError ee = new IllegalAccessError("Failed to access special method " + methodDescription( + declaringClass, name, type)); + ee.initCause(e); + throw ee; + } catch(final NoSuchMethodException e) { + final NoSuchMethodError ee = new NoSuchMethodError("Failed to find special method " + methodDescription( + declaringClass, name, type)); + ee.initCause(e); + throw ee; + } + } + + private static String methodDescription(final Class declaringClass, final String name, final MethodType type) { + return declaringClass.getName() + "#" + name + type; + } + + /** + * Performs a {@link java.lang.invoke.MethodHandles.Lookup#findStatic(Class, String, MethodType)} + * on the underlying lookup. Converts any encountered + * {@link IllegalAccessException} into an {@link IllegalAccessError} and + * {@link NoSuchMethodException} into a {@link NoSuchMethodError}. + * + * @param declaringClass class declaring the method + * @param name the name of the method + * @param type the type of the method + * @return a method handle for the method + * @throws IllegalAccessError if the method is inaccessible. + * @throws NoSuchMethodError if the method does not exist. + */ + public MethodHandle findStatic(final Class declaringClass, final String name, final MethodType type) { + try { + return lookup.findStatic(declaringClass, name, type); + } catch(final IllegalAccessException e) { + final IllegalAccessError ee = new IllegalAccessError("Failed to access static method " + methodDescription( + declaringClass, name, type)); + ee.initCause(e); + throw ee; + } catch(final NoSuchMethodException e) { + final NoSuchMethodError ee = new NoSuchMethodError("Failed to find static method " + methodDescription( + declaringClass, name, type)); + ee.initCause(e); + throw ee; + } + } + + /** + * Performs a {@link java.lang.invoke.MethodHandles.Lookup#findVirtual(Class, String, MethodType)} + * on the underlying lookup. Converts any encountered + * {@link IllegalAccessException} into an {@link IllegalAccessError} and + * {@link NoSuchMethodException} into a {@link NoSuchMethodError}. + * + * @param declaringClass class declaring the method + * @param name the name of the method + * @param type the type of the method + * @return a method handle for the method + * @throws IllegalAccessError if the method is inaccessible. + * @throws NoSuchMethodError if the method does not exist. + */ + public MethodHandle findVirtual(final Class declaringClass, final String name, final MethodType type) { + try { + return lookup.findVirtual(declaringClass, name, type); + } catch(final IllegalAccessException e) { + final IllegalAccessError ee = new IllegalAccessError("Failed to access virtual method " + methodDescription( + declaringClass, name, type)); + ee.initCause(e); + throw ee; + } catch(final NoSuchMethodException e) { + final NoSuchMethodError ee = new NoSuchMethodError("Failed to find virtual method " + methodDescription( + declaringClass, name, type)); + ee.initCause(e); + throw ee; + } + } + + /** + * Given a lookup, finds using {@link #findSpecial(Class, String, MethodType)} + * a method on that lookup's class. Useful in classes' code for convenient + * linking to their own privates. + * @param lookup the lookup for the class + * @param name the name of the method + * @param rtype the return type of the method + * @param ptypes the parameter types of the method + * @return the method handle for the method + */ + public static MethodHandle findOwnSpecial(final MethodHandles.Lookup lookup, final String name, final Class rtype, final Class... ptypes) { + return new Lookup(lookup).findOwnSpecial(name, rtype, ptypes); + } + + + /** + * Finds using {@link #findSpecial(Class, String, MethodType)} a method on + * that lookup's class. Useful in classes' code for convenient linking to + * their own privates. It's also more convenient than {@code findSpecial} + * in that you can just list the parameter types, and don't have to specify + * lookup class. + * @param name the name of the method + * @param rtype the return type of the method + * @param ptypes the parameter types of the method + * @return the method handle for the method + */ + public MethodHandle findOwnSpecial(final String name, final Class rtype, final Class... ptypes) { + return findSpecial(lookup.lookupClass(), name, MethodType.methodType(rtype, ptypes)); + } + + /** + * Given a lookup, finds using {@link #findStatic(Class, String, MethodType)} + * a method on that lookup's class. Useful in classes' code for convenient + * linking to their own privates. It's easier to use than {@code findStatic} + * in that you can just list the parameter types, and don't have to specify + * lookup class. + * @param lookup the lookup for the class + * @param name the name of the method + * @param rtype the return type of the method + * @param ptypes the parameter types of the method + * @return the method handle for the method + */ + public static MethodHandle findOwnStatic(final MethodHandles.Lookup lookup, final String name, final Class rtype, final Class... ptypes) { + return new Lookup(lookup).findOwnStatic(name, rtype, ptypes); + } + + /** + * Finds using {@link #findStatic(Class, String, MethodType)} a method on + * that lookup's class. Useful in classes' code for convenient linking to + * their own privates. It's easier to use than {@code findStatic} + * in that you can just list the parameter types, and don't have to specify + * lookup class. + * @param name the name of the method + * @param rtype the return type of the method + * @param ptypes the parameter types of the method + * @return the method handle for the method + */ + public MethodHandle findOwnStatic(final String name, final Class rtype, final Class... ptypes) { + return findStatic(lookup.lookupClass(), name, MethodType.methodType(rtype, ptypes)); + } +} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/SimpleLinkRequest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/SimpleLinkRequest.java Tue Oct 20 23:33:18 2015 +0200 @@ -0,0 +1,136 @@ +/* + * 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.linker.support; + +import jdk.internal.dynalink.CallSiteDescriptor; +import jdk.internal.dynalink.linker.LinkRequest; + +/** + * Default simple implementation of {@link LinkRequest}. + */ +public class SimpleLinkRequest implements LinkRequest { + + private final CallSiteDescriptor callSiteDescriptor; + private final Object[] arguments; + private final boolean callSiteUnstable; + + /** + * Creates a new link request. + * + * @param callSiteDescriptor the descriptor for the call site being linked. + * @param callSiteUnstable true if the call site being linked is considered + * unstable. + * @param arguments the arguments for the invocation + */ + public SimpleLinkRequest(final CallSiteDescriptor callSiteDescriptor, final boolean callSiteUnstable, final Object... arguments) { + this.callSiteDescriptor = callSiteDescriptor; + this.callSiteUnstable = callSiteUnstable; + this.arguments = arguments; + } + + @Override + public Object[] getArguments() { + return arguments != null ? arguments.clone() : null; + } + + @Override + public Object getReceiver() { + return arguments != null && arguments.length > 0 ? arguments[0] : null; + } + + @Override + public CallSiteDescriptor getCallSiteDescriptor() { + return callSiteDescriptor; + } + + @Override + public boolean isCallSiteUnstable() { + return callSiteUnstable; + } + + @Override + public LinkRequest replaceArguments(final CallSiteDescriptor newCallSiteDescriptor, final Object[] newArguments) { + return new SimpleLinkRequest(newCallSiteDescriptor, callSiteUnstable, newArguments); + } +} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/TypeUtilities.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/TypeUtilities.java Tue Oct 20 23:33:18 2015 +0200 @@ -0,0 +1,530 @@ +/* + * 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.linker.support; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Various static utility methods for testing type relationships. + */ +public class TypeUtilities { + static final Class OBJECT_CLASS = Object.class; + + private TypeUtilities() { + } + + /** + * Given two types represented by c1 and c2, returns a type that is their most specific common supertype for + * purposes of lossless conversions. + * + * @param c1 one type + * @param c2 another type + * @return their most common superclass or superinterface for purposes of lossless conversions. If they have several + * unrelated superinterfaces as their most specific common type, or the types themselves are completely + * unrelated interfaces, {@link java.lang.Object} is returned. + */ + public static Class getCommonLosslessConversionType(final Class c1, final Class c2) { + if(c1 == c2) { + return c1; + } else if (c1 == void.class || c2 == void.class) { + return Object.class; + } else if(isConvertibleWithoutLoss(c2, c1)) { + return c1; + } else if(isConvertibleWithoutLoss(c1, c2)) { + return c2; + } else if(c1.isPrimitive() && c2.isPrimitive()) { + if((c1 == byte.class && c2 == char.class) || (c1 == char.class && c2 == byte.class)) { + // byte + char = int + return int.class; + } else if((c1 == short.class && c2 == char.class) || (c1 == char.class && c2 == short.class)) { + // short + char = int + return int.class; + } else if((c1 == int.class && c2 == float.class) || (c1 == float.class && c2 == int.class)) { + // int + float = double + return double.class; + } + } + // For all other cases. This will handle long + (float|double) = Number case as well as boolean + anything = Object case too. + return getMostSpecificCommonTypeUnequalNonprimitives(c1, c2); + } + + private static Class getMostSpecificCommonTypeUnequalNonprimitives(final Class c1, final Class c2) { + final Class npc1 = c1.isPrimitive() ? getWrapperType(c1) : c1; + final Class npc2 = c2.isPrimitive() ? getWrapperType(c2) : c2; + final Set> a1 = getAssignables(npc1, npc2); + final Set> a2 = getAssignables(npc2, npc1); + a1.retainAll(a2); + if(a1.isEmpty()) { + // Can happen when at least one of the arguments is an interface, + // as they don't have Object at the root of their hierarchy. + return Object.class; + } + // Gather maximally specific elements. Yes, there can be more than one + // thank to interfaces. I.e., if you call this method for String.class + // and Number.class, you'll have Comparable, Serializable, and Object + // as maximal elements. + final List> max = new ArrayList<>(); + outer: for(final Class clazz: a1) { + for(final Iterator> maxiter = max.iterator(); maxiter.hasNext();) { + final Class maxClazz = maxiter.next(); + if(isSubtype(maxClazz, clazz)) { + // It can't be maximal, if there's already a more specific + // maximal than it. + continue outer; + } + if(isSubtype(clazz, maxClazz)) { + // If it's more specific than a currently maximal element, + // that currently maximal is no longer a maximal. + maxiter.remove(); + } + } + // If we get here, no current maximal is more specific than the + // current class, so it is considered maximal as well + max.add(clazz); + } + if(max.size() > 1) { + return Object.class; + } + return max.get(0); + } + + private static Set> getAssignables(final Class c1, final Class c2) { + final Set> s = new HashSet<>(); + collectAssignables(c1, c2, s); + return s; + } + + private static void collectAssignables(final Class c1, final Class c2, final Set> s) { + if(c1.isAssignableFrom(c2)) { + s.add(c1); + } + final Class sc = c1.getSuperclass(); + if(sc != null) { + collectAssignables(sc, c2, s); + } + final Class[] itf = c1.getInterfaces(); + for(int i = 0; i < itf.length; ++i) { + collectAssignables(itf[i], c2, s); + } + } + + private static final Map, Class> WRAPPER_TYPES = createWrapperTypes(); + private static final Map, Class> PRIMITIVE_TYPES = invertMap(WRAPPER_TYPES); + private static final Map> PRIMITIVE_TYPES_BY_NAME = createClassNameMapping(WRAPPER_TYPES.keySet()); + + private static Map, Class> createWrapperTypes() { + final Map, Class> wrapperTypes = new IdentityHashMap<>(8); + wrapperTypes.put(Boolean.TYPE, Boolean.class); + wrapperTypes.put(Byte.TYPE, Byte.class); + wrapperTypes.put(Character.TYPE, Character.class); + wrapperTypes.put(Short.TYPE, Short.class); + wrapperTypes.put(Integer.TYPE, Integer.class); + wrapperTypes.put(Long.TYPE, Long.class); + wrapperTypes.put(Float.TYPE, Float.class); + wrapperTypes.put(Double.TYPE, Double.class); + return Collections.unmodifiableMap(wrapperTypes); + } + + private static Map> createClassNameMapping(final Collection> classes) { + final Map> map = new HashMap<>(); + for(final Class clazz: classes) { + map.put(clazz.getName(), clazz); + } + return map; + } + + private static Map invertMap(final Map map) { + final Map inverted = new IdentityHashMap<>(map.size()); + for(final Map.Entry entry: map.entrySet()) { + inverted.put(entry.getValue(), entry.getKey()); + } + return Collections.unmodifiableMap(inverted); + } + + /** + * Determines whether one type can be converted to another type using a method invocation conversion, as per JLS 5.3 + * "Method Invocation Conversion". This is basically all conversions allowed by subtyping (see + * {@link #isSubtype(Class, Class)}) as well as boxing conversion (JLS 5.1.7) optionally followed by widening + * reference conversion and unboxing conversion (JLS 5.1.8) optionally followed by widening primitive conversion. + * + * @param sourceType the type being converted from (call site type for parameter types, method type for return types) + * @param targetType the parameter type being converted to (method type for parameter types, call site type for return types) + * @return true if source type is method invocation convertible to target type. + */ + public static boolean isMethodInvocationConvertible(final Class sourceType, final Class targetType) { + if(targetType.isAssignableFrom(sourceType)) { + return true; + } + if(sourceType.isPrimitive()) { + if(targetType.isPrimitive()) { + return isProperPrimitiveSubtype(sourceType, targetType); + } + // Boxing + widening reference conversion + assert WRAPPER_TYPES.get(sourceType) != null : sourceType.getName(); + return targetType.isAssignableFrom(WRAPPER_TYPES.get(sourceType)); + } + if(targetType.isPrimitive()) { + final Class unboxedCallSiteType = PRIMITIVE_TYPES.get(sourceType); + return unboxedCallSiteType != null + && (unboxedCallSiteType == targetType || isProperPrimitiveSubtype(unboxedCallSiteType, targetType)); + } + return false; + } + + /** + * Determines whether a type can be converted to another without losing any precision. As a special case, + * void is considered convertible only to Object and void, while anything can be converted to void. This + * is because a target type of void means we don't care about the value, so the conversion is always + * permissible. + * + * @param sourceType the source type + * @param targetType the target type + * @return true if lossless conversion is possible + */ + public static boolean isConvertibleWithoutLoss(final Class sourceType, final Class targetType) { + if(targetType.isAssignableFrom(sourceType) || targetType == void.class) { + return true; + } + if(sourceType.isPrimitive()) { + if(sourceType == void.class) { + // Void should be losslessly representable by Object, either as null or as a custom value that + // can be set with DynamicLinkerFactory.setAutoConversionStrategy. + return targetType == Object.class; + } + if(targetType.isPrimitive()) { + return isProperPrimitiveLosslessSubtype(sourceType, targetType); + } + // Boxing + widening reference conversion + assert WRAPPER_TYPES.get(sourceType) != null : sourceType.getName(); + return targetType.isAssignableFrom(WRAPPER_TYPES.get(sourceType)); + } + // Can't convert from any non-primitive type to any primitive type without data loss because of null. + // Also, can't convert non-assignable reference types. + return false; + } + + /** + * Determines whether one type can be potentially converted to another type at runtime. Allows a conversion between + * any subtype and supertype in either direction, and also allows a conversion between any two primitive types, as + * well as between any primitive type and any reference type that can hold a boxed primitive. + * + * @param callSiteType the parameter type at the call site + * @param methodType the parameter type in the method declaration + * @return true if callSiteType is potentially convertible to the methodType. + */ + public static boolean isPotentiallyConvertible(final Class callSiteType, final Class methodType) { + // Widening or narrowing reference conversion + if(areAssignable(callSiteType, methodType)) { + return true; + } + if(callSiteType.isPrimitive()) { + // Allow any conversion among primitives, as well as from any + // primitive to any type that can receive a boxed primitive. + // TODO: narrow this a bit, i.e. allow, say, boolean to Character? + // MethodHandles.convertArguments() allows it, so we might need to + // too. + return methodType.isPrimitive() || isAssignableFromBoxedPrimitive(methodType); + } + if(methodType.isPrimitive()) { + // Allow conversion from any reference type that can contain a + // boxed primitive to any primitive. + // TODO: narrow this a bit too? + return isAssignableFromBoxedPrimitive(callSiteType); + } + return false; + } + + /** + * Returns true if either of the types is assignable from the other. + * @param c1 one of the types + * @param c2 another one of the types + * @return true if either c1 is assignable from c2 or c2 is assignable from c1. + */ + public static boolean areAssignable(final Class c1, final Class c2) { + return c1.isAssignableFrom(c2) || c2.isAssignableFrom(c1); + } + + /** + * Determines whether one type is a subtype of another type, as per JLS 4.10 "Subtyping". Note: this is not strict + * or proper subtype, therefore true is also returned for identical types; to be completely precise, it allows + * identity conversion (JLS 5.1.1), widening primitive conversion (JLS 5.1.2) and widening reference conversion (JLS + * 5.1.5). + * + * @param subType the supposed subtype + * @param superType the supposed supertype of the subtype + * @return true if subType can be converted by identity conversion, widening primitive conversion, or widening + * reference conversion to superType. + */ + public static boolean isSubtype(final Class subType, final Class superType) { + // Covers both JLS 4.10.2 "Subtyping among Class and Interface Types" + // and JLS 4.10.3 "Subtyping among Array Types", as well as primitive + // type identity. + if(superType.isAssignableFrom(subType)) { + return true; + } + // JLS 4.10.1 "Subtyping among Primitive Types". Note we don't test for + // identity, as identical types were taken care of in the + // isAssignableFrom test. As per 4.10.1, the supertype relation is as + // follows: + // double > float + // float > long + // long > int + // int > short + // int > char + // short > byte + if(superType.isPrimitive() && subType.isPrimitive()) { + return isProperPrimitiveSubtype(subType, superType); + } + return false; + } + + /** + * Returns true if a supposed primitive subtype is a proper subtype ( meaning, subtype and not identical) of the + * supposed primitive supertype + * + * @param subType the supposed subtype + * @param superType the supposed supertype + * @return true if subType is a proper (not identical to) primitive subtype of the superType + */ + private static boolean isProperPrimitiveSubtype(final Class subType, final Class superType) { + if(superType == boolean.class || subType == boolean.class) { + return false; + } + if(subType == byte.class) { + return superType != char.class; + } + if(subType == char.class) { + return superType != short.class && superType != byte.class; + } + if(subType == short.class) { + return superType != char.class && superType != byte.class; + } + if(subType == int.class) { + return superType == long.class || superType == float.class || superType == double.class; + } + if(subType == long.class) { + return superType == float.class || superType == double.class; + } + if(subType == float.class) { + return superType == double.class; + } + return false; + } + + /** + * Similar to {@link #isProperPrimitiveSubtype(Class, Class)}, except it disallows conversions from int and long to + * float, and from long to double, as those can lose precision. It also disallows conversion from and to char and + * anything else (similar to boolean) as char is not meant to be an arithmetic type. + * @param subType the supposed subtype + * @param superType the supposed supertype + * @return true if subType is a proper (not identical to) primitive subtype of the superType that can be represented + * by the supertype without no precision loss. + */ + private static boolean isProperPrimitiveLosslessSubtype(final Class subType, final Class superType) { + if(superType == boolean.class || subType == boolean.class) { + return false; + } + if(superType == char.class || subType == char.class) { + return false; + } + if(subType == byte.class) { + return true; + } + if(subType == short.class) { + return superType != byte.class; + } + if(subType == int.class) { + return superType == long.class || superType == double.class; + } + if(subType == float.class) { + return superType == double.class; + } + return false; + } + + private static final Map, Class> WRAPPER_TO_PRIMITIVE_TYPES = createWrapperToPrimitiveTypes(); + + private static Map, Class> createWrapperToPrimitiveTypes() { + final Map, Class> classes = new IdentityHashMap<>(); + classes.put(Void.class, Void.TYPE); + classes.put(Boolean.class, Boolean.TYPE); + classes.put(Byte.class, Byte.TYPE); + classes.put(Character.class, Character.TYPE); + classes.put(Short.class, Short.TYPE); + classes.put(Integer.class, Integer.TYPE); + classes.put(Long.class, Long.TYPE); + classes.put(Float.class, Float.TYPE); + classes.put(Double.class, Double.TYPE); + return classes; + } + + private static final Set> PRIMITIVE_WRAPPER_TYPES = createPrimitiveWrapperTypes(); + + private static Set> createPrimitiveWrapperTypes() { + final Map, Class> classes = new IdentityHashMap<>(); + addClassHierarchy(classes, Boolean.class); + addClassHierarchy(classes, Byte.class); + addClassHierarchy(classes, Character.class); + addClassHierarchy(classes, Short.class); + addClassHierarchy(classes, Integer.class); + addClassHierarchy(classes, Long.class); + addClassHierarchy(classes, Float.class); + addClassHierarchy(classes, Double.class); + return classes.keySet(); + } + + private static void addClassHierarchy(final Map, Class> map, final Class clazz) { + if(clazz == null) { + return; + } + map.put(clazz, clazz); + addClassHierarchy(map, clazz.getSuperclass()); + for(final Class itf: clazz.getInterfaces()) { + addClassHierarchy(map, itf); + } + } + + /** + * Returns true if the class can be assigned from any boxed primitive. + * + * @param clazz the class + * @return true if the class can be assigned from any boxed primitive. Basically, it is true if the class is any + * primitive wrapper class, or a superclass or superinterface of any primitive wrapper class. + */ + private static boolean isAssignableFromBoxedPrimitive(final Class clazz) { + return PRIMITIVE_WRAPPER_TYPES.contains(clazz); + } + + /** + * Given a name of a primitive type (except "void"), returns the class representing it. I.e. when invoked with + * "int", returns {@link Integer#TYPE}. + * @param name the name of the primitive type + * @return the class representing the primitive type, or null if the name does not correspond to a primitive type + * or is "void". + */ + public static Class getPrimitiveTypeByName(final String name) { + return PRIMITIVE_TYPES_BY_NAME.get(name); + } + + /** + * When passed a class representing a wrapper for a primitive type, returns the class representing the corresponding + * primitive type. I.e. calling it with {@code Integer.class} will return {@code Integer.TYPE}. If passed a class + * that is not a wrapper for primitive type, returns null. + * @param wrapperType the class object representing a wrapper for a primitive type + * @return the class object representing the primitive type, or null if the passed class is not a primitive wrapper. + */ + public static Class getPrimitiveType(final Class wrapperType) { + return WRAPPER_TO_PRIMITIVE_TYPES.get(wrapperType); + } + + + /** + * When passed a class representing a primitive type, returns the class representing the corresponding + * wrapper type. I.e. calling it with {@code int.class} will return {@code Integer.class}. If passed a class + * that is not a primitive type, returns null. + * @param primitiveType the class object representing a primitive type + * @return the class object representing the wrapper type, or null if the passed class is not a primitive. + */ + public static Class getWrapperType(final Class primitiveType) { + return WRAPPER_TYPES.get(primitiveType); + } + + /** + * Returns true if the passed type is a wrapper for a primitive type. + * @param type the examined type + * @return true if the passed type is a wrapper for a primitive type. + */ + public static boolean isWrapperType(final Class type) { + return PRIMITIVE_TYPES.containsKey(type); + } +} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/ChainedCallSite.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/ChainedCallSite.java Tue Oct 20 23:33:18 2015 +0200 @@ -0,0 +1,244 @@ +/* + * 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.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; +import jdk.internal.dynalink.CallSiteDescriptor; +import jdk.internal.dynalink.linker.GuardedInvocation; +import jdk.internal.dynalink.linker.support.Lookup; + +/** + * A relinkable call site that implements a polymorphic inline caching strategy. + * It remembers up to 8 {@link GuardedInvocation}s it was linked with, and on + * each relink request builds a cascading chain of method handles of one + * invocation falling back to the next one. The number of remembered invocations + * can be customized by overriding {@link #getMaxChainLength()} in a subclass. + * When this call site is relinked with a new invocation and the length of the + * chain is already at the maximum, it will throw away the oldest invocation. + * Invocations with invalidated switch points and ones for which their + * invalidating exception triggered are removed eagerly from the chain. The + * invocations are never reordered; the most recently linked method handle is + * always at the start of the chain and the least recently linked at its end. + * The call site can be safely relinked on more than one thread concurrently. + * Race conditions in linking are resolved by throwing away the + * {@link GuardedInvocation} produced on the losing thread without incorporating + * it into the chain, so it can lead to repeated linking for the same arguments. + */ +public class ChainedCallSite extends AbstractRelinkableCallSite { + private static final MethodHandle PRUNE_CATCHES; + private static final MethodHandle PRUNE_SWITCHPOINTS; + static { + final MethodHandle PRUNE = Lookup.findOwnSpecial(MethodHandles.lookup(), "prune", MethodHandle.class, + MethodHandle.class, boolean.class); + PRUNE_CATCHES = MethodHandles.insertArguments(PRUNE, 2, true); + PRUNE_SWITCHPOINTS = MethodHandles.insertArguments(PRUNE, 2, false); + } + + /** + * Contains the invocations currently linked into this call site's target. They are used when we are + * relinking to rebuild the guardWithTest chain. Valid values for this field are: {@code null} if there's + * no linked invocations, or an instance of {@link GuardedInvocation} if there is exactly one previous + * invocation, or an instance of {@code GuardedInvocation[]} if there is more than one previous + * invocation. + */ + private Object invocations; + + /** + * Creates a new chained call site. + * @param descriptor the descriptor for the call site. + */ + public ChainedCallSite(final CallSiteDescriptor descriptor) { + super(descriptor); + } + + /** + * The maximum number of method handles in the chain. Defaults to 8. You can + * override it in a subclass if you need to change the value. + * @return the maximum number of method handles in the chain. The return + * value is checked, and if your override returns a value less than 1, a + * {@link RuntimeException} will be thrown. + */ + protected int getMaxChainLength() { + return 8; + } + + @Override + public void relink(final GuardedInvocation guardedInvocation, final MethodHandle relinkAndInvoke) { + relinkInternal(guardedInvocation, relinkAndInvoke, false, false); + } + + @Override + public void resetAndRelink(final GuardedInvocation guardedInvocation, final MethodHandle relinkAndInvoke) { + relinkInternal(guardedInvocation, relinkAndInvoke, true, false); + } + + private MethodHandle relinkInternal(final GuardedInvocation invocation, final MethodHandle relink, final boolean reset, final boolean removeCatches) { + final Object currentInvocations = invocations; + final LinkedList newInvocations; + if (currentInvocations == null || reset) { + newInvocations = new LinkedList<>(); + } else if (currentInvocations instanceof GuardedInvocation) { + newInvocations = new LinkedList<>(); + newInvocations.add((GuardedInvocation)currentInvocations); + } else if (currentInvocations instanceof GuardedInvocation[]) { + newInvocations = new LinkedList<>(Arrays.asList(((GuardedInvocation[])currentInvocations))); + } else { + throw new AssertionError(); + } + + // First, prune the chain of invalidated switchpoints, we always do this + // We also remove any catches if the remove catches flag is set + for(final Iterator it = newInvocations.iterator(); it.hasNext();) { + final GuardedInvocation inv = it.next(); + if(inv.hasBeenInvalidated() || (removeCatches && inv.getException() != null)) { + it.remove(); + } + } + + // prune() is allowed to invoke this method with invocation == null meaning we're just pruning the chain and not + // adding any new invocations to it. + if(invocation != null) { + // Remove oldest entry if we're at max length + if(newInvocations.size() == checkMaxChainLength(getMaxChainLength())) { + newInvocations.removeFirst(); + } + newInvocations.addLast(invocation); + } + + // prune-and-invoke is used as the fallback for invalidated switchpoints. If a switchpoint gets invalidated, we + // rebuild the chain and get rid of all invalidated switchpoints instead of letting them linger. + final MethodHandle pruneAndInvokeSwitchPoints = makePruneAndInvokeMethod(relink, PRUNE_SWITCHPOINTS); + final MethodHandle pruneAndInvokeCatches = makePruneAndInvokeMethod(relink, PRUNE_CATCHES); + + // Fold the new chain + MethodHandle target = relink; + for(final GuardedInvocation inv: newInvocations) { + target = inv.compose(target, pruneAndInvokeSwitchPoints, pruneAndInvokeCatches); + } + + switch (newInvocations.size()) { + case 0: + invocations = null; + break; + case 1: + invocations = newInvocations.getFirst(); + break; + default: + invocations = newInvocations.toArray(new GuardedInvocation[newInvocations.size()]); + } + setTarget(target); + 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. + * @param relinkAndInvoke the ultimate fallback for the chain passed from the dynamic linker. + * @return a method handle for prune-and-invoke + */ + private MethodHandle makePruneAndInvokeMethod(final MethodHandle relinkAndInvoke, final MethodHandle prune) { + // Bind prune to (this, relink) + final MethodHandle boundPrune = MethodHandles.insertArguments(prune, 0, this, relinkAndInvoke); + // Make it ignore all incoming arguments + final MethodHandle ignoreArgsPrune = MethodHandles.dropArguments(boundPrune, 0, type().parameterList()); + // Invoke prune, then invoke the call site target with original arguments + return MethodHandles.foldArguments(MethodHandles.exactInvoker(type()), ignoreArgsPrune); + } + + @SuppressWarnings("unused") + private MethodHandle prune(final MethodHandle relink, final boolean catches) { + return relinkInternal(null, relink, false, catches); + } +} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CompositeGuardingDynamicLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CompositeGuardingDynamicLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +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.io.Serializable; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; -import jdk.internal.dynalink.linker.GuardedInvocation; -import jdk.internal.dynalink.linker.GuardingDynamicLinker; -import jdk.internal.dynalink.linker.LinkRequest; -import jdk.internal.dynalink.linker.LinkerServices; - -/** - * A {@link GuardingDynamicLinker} that delegates sequentially to a list of - * other guarding dynamic linkers in its - * {@link #getGuardedInvocation(LinkRequest, LinkerServices)}. - */ -public class CompositeGuardingDynamicLinker implements GuardingDynamicLinker, Serializable { - - private static final long serialVersionUID = 1L; - - private final GuardingDynamicLinker[] linkers; - - /** - * Creates a new composite linker. - * - * @param linkers a list of component linkers. - * @throws NullPointerException if {@code linkers} or any of its elements - * are null. - */ - public CompositeGuardingDynamicLinker(final Iterable linkers) { - final List l = new LinkedList<>(); - for(final GuardingDynamicLinker linker: linkers) { - l.add(Objects.requireNonNull(linker)); - } - this.linkers = l.toArray(new GuardingDynamicLinker[l.size()]); - } - - /** - * Delegates the call to its component linkers. The first non-null value - * returned from a component linker is returned. If no component linker - * returns a non-null invocation, null is returned. - * @param linkRequest the object describing the request for linking a - * particular invocation - * @param linkerServices linker services - * @return the first non-null return value from a component linker, or null - * if none of the components returned a non-null. - */ - @Override - public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) - throws Exception { - for(final GuardingDynamicLinker linker: linkers) { - final GuardedInvocation invocation = linker.getGuardedInvocation(linkRequest, linkerServices); - if(invocation != null) { - return invocation; - } - } - return null; - } -} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CompositeTypeBasedGuardingDynamicLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CompositeTypeBasedGuardingDynamicLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,239 +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.io.Serializable; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; -import jdk.internal.dynalink.linker.GuardedInvocation; -import jdk.internal.dynalink.linker.GuardingDynamicLinker; -import jdk.internal.dynalink.linker.LinkRequest; -import jdk.internal.dynalink.linker.LinkerServices; -import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker; - -/** - * A composite type-based guarding dynamic linker. When a receiver of a not yet - * seen class is encountered, all linkers are queried sequentially on their - * {@link TypeBasedGuardingDynamicLinker#canLinkType(Class)} method. The linkers - * returning true are then bound to the class, and next time a receiver of same - * type is encountered, the linking is delegated to those linkers only, speeding - * up dispatch. - */ -public class CompositeTypeBasedGuardingDynamicLinker implements TypeBasedGuardingDynamicLinker, Serializable { - private static final long serialVersionUID = 1L; - - // Using a separate static class instance so there's no strong reference from the class value back to the composite - // linker. - private static class ClassToLinker extends ClassValue> { - private static final List NO_LINKER = Collections.emptyList(); - private final TypeBasedGuardingDynamicLinker[] linkers; - private final List[] singletonLinkers; - - @SuppressWarnings({"unchecked", "rawtypes"}) - ClassToLinker(final TypeBasedGuardingDynamicLinker[] linkers) { - this.linkers = linkers; - singletonLinkers = new List[linkers.length]; - for(int i = 0; i < linkers.length; ++i) { - singletonLinkers[i] = Collections.singletonList(linkers[i]); - } - } - - @SuppressWarnings("fallthrough") - @Override - protected List computeValue(final Class clazz) { - List list = NO_LINKER; - for(int i = 0; i < linkers.length; ++i) { - final TypeBasedGuardingDynamicLinker linker = linkers[i]; - if(linker.canLinkType(clazz)) { - switch(list.size()) { - case 0: { - list = singletonLinkers[i]; - break; - } - case 1: { - list = new LinkedList<>(list); - } - default: { - list.add(linker); - } - } - } - } - return list; - } - } - - private final ClassValue> classToLinker; - - /** - * Creates a new composite type-based linker. - * - * @param linkers the component linkers - * @throws NullPointerException if {@code linkers} or any of its elements - * are null. - */ - public CompositeTypeBasedGuardingDynamicLinker(final Iterable linkers) { - final List l = new LinkedList<>(); - for(final TypeBasedGuardingDynamicLinker linker: linkers) { - l.add(Objects.requireNonNull(linker)); - } - this.classToLinker = new ClassToLinker(l.toArray(new TypeBasedGuardingDynamicLinker[l.size()])); - } - - /** - * Returns true if any of the composite linkers return true from - * {@link TypeBasedGuardingDynamicLinker#canLinkType(Class)} for the type. - * @param type the type to link - * @return true if any of the composite linkers can link calls for the - * receiver type, false otherwise. - */ - @Override - public boolean canLinkType(final Class type) { - return !classToLinker.get(type).isEmpty(); - } - - @Override - public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) - throws Exception { - final Object obj = linkRequest.getReceiver(); - if(obj == null) { - return null; - } - for(final TypeBasedGuardingDynamicLinker linker: classToLinker.get(obj.getClass())) { - final GuardedInvocation invocation = linker.getGuardedInvocation(linkRequest, linkerServices); - if(invocation != null) { - return invocation; - } - } - return null; - } - - /** - * Optimizes a list of type-based linkers. If a group of adjacent linkers in - * the list all implement {@link TypeBasedGuardingDynamicLinker}, they will - * be replaced with a single instance of - * {@link CompositeTypeBasedGuardingDynamicLinker} that contains them. - * - * @param linkers the list of linkers to optimize - * @return the optimized list - * @throws NullPointerException if {@code linkers} or any of its elements - * are null. - */ - public static List optimize(final Iterable linkers) { - final List llinkers = new LinkedList<>(); - final List tblinkers = new LinkedList<>(); - for(final GuardingDynamicLinker linker: linkers) { - Objects.requireNonNull(linker); - if(linker instanceof TypeBasedGuardingDynamicLinker) { - tblinkers.add((TypeBasedGuardingDynamicLinker)linker); - } else { - addTypeBased(llinkers, tblinkers); - llinkers.add(linker); - } - } - addTypeBased(llinkers, tblinkers); - return llinkers; - } - - private static void addTypeBased(final List llinkers, - final List tblinkers) { - switch(tblinkers.size()) { - case 0: { - break; - } - case 1: { - llinkers.addAll(tblinkers); - tblinkers.clear(); - break; - } - default: { - llinkers.add(new CompositeTypeBasedGuardingDynamicLinker(tblinkers)); - tblinkers.clear(); - break; - } - } - } -} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/DefaultInternalObjectFilter.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/DefaultInternalObjectFilter.java Mon Oct 19 22:36:03 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,185 +0,0 @@ -/* - * 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 - * 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-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 - 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.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import jdk.internal.dynalink.DynamicLinkerFactory; -import jdk.internal.dynalink.linker.MethodHandleTransformer; - -/** - * Default implementation for a - * {@link DynamicLinkerFactory#setInternalObjectsFilter(MethodHandleTransformer)} - * that delegates to a pair of filtering method handles. Given a method handle - * of {@code Object(Object)} type for filtering parameter and another one of the - * same type for filtering return values, applies them to passed method handles, - * on those parameter types and/or return value types that are declared to be - * {@link Object}. Also handles {@link MethodHandle#isVarargsCollector() method - * handles that support variable arity calls} with a last {@code Object[]} - * parameter. - */ -public class DefaultInternalObjectFilter implements MethodHandleTransformer { - private static final MethodHandle FILTER_VARARGS = new Lookup(MethodHandles.lookup()).findStatic( - DefaultInternalObjectFilter.class, "filterVarArgs", MethodType.methodType(Object[].class, MethodHandle.class, Object[].class)); - - private final MethodHandle parameterFilter; - private final MethodHandle returnFilter; - private final MethodHandle varArgFilter; - - /** - * Creates a new filter. - * @param parameterFilter the filter for method parameters. Must be of type - * {@code Object(Object)}, or {@code null}. - * @param returnFilter the filter for return values. Must be of type - * {@code Object(Object)}, or {@code null}. - * @throws IllegalArgumentException if one or both filters are not of the - * expected type. - */ - public DefaultInternalObjectFilter(final MethodHandle parameterFilter, final MethodHandle returnFilter) { - this.parameterFilter = checkHandle(parameterFilter, "parameterFilter"); - this.returnFilter = checkHandle(returnFilter, "returnFilter"); - this.varArgFilter = parameterFilter == null ? null : FILTER_VARARGS.bindTo(parameterFilter); - } - - @Override - public MethodHandle transform(final MethodHandle target) { - assert target != null; - MethodHandle[] filters = null; - final MethodType type = target.type(); - final boolean isVarArg = target.isVarargsCollector(); - final int paramCount = type.parameterCount(); - final MethodHandle paramsFiltered; - // Filter parameters - if (parameterFilter != null) { - int firstFilter = -1; - // Ignore receiver, start from argument 1 - for(int i = 1; i < paramCount; ++i) { - final Class paramType = type.parameterType(i); - final boolean filterVarArg = isVarArg && i == paramCount - 1 && paramType == Object[].class; - if (filterVarArg || paramType == Object.class) { - if (filters == null) { - firstFilter = i; - filters = new MethodHandle[paramCount - firstFilter]; - } - filters[i - firstFilter] = filterVarArg ? varArgFilter : parameterFilter; - } - } - paramsFiltered = filters != null ? MethodHandles.filterArguments(target, firstFilter, filters) : target; - } else { - paramsFiltered = target; - } - // Filter return value if needed - final MethodHandle returnFiltered = returnFilter != null && type.returnType() == Object.class ? MethodHandles.filterReturnValue(paramsFiltered, returnFilter) : paramsFiltered; - // Preserve varargs collector state - return isVarArg && !returnFiltered.isVarargsCollector() ? returnFiltered.asVarargsCollector(type.parameterType(paramCount - 1)) : returnFiltered; - - } - - private static MethodHandle checkHandle(final MethodHandle handle, final String handleKind) { - if (handle != null) { - final MethodType objectObjectType = MethodType.methodType(Object.class, Object.class); - if (!handle.type().equals(objectObjectType)) { - throw new IllegalArgumentException("Method type for " + handleKind + " must be " + objectObjectType); - } - } - return handle; - } - - @SuppressWarnings("unused") - private static Object[] filterVarArgs(final MethodHandle parameterFilter, final Object[] args) throws Throwable { - Object[] newArgs = null; - for(int i = 0; i < args.length; ++i) { - final Object arg = args[i]; - final Object newArg = parameterFilter.invokeExact(arg); - if (arg != newArg) { - if (newArgs == null) { - newArgs = args.clone(); - } - newArgs[i] = newArg; - } - } - return newArgs == null ? args : newArgs; - } -} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/Guards.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/Guards.java Mon Oct 19 22:36:03 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,359 +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.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.util.logging.Level; -import java.util.logging.Logger; -import jdk.internal.dynalink.DynamicLinker; -import jdk.internal.dynalink.linker.LinkerServices; - -/** - * Utility methods for creating typical guards. - */ -public final class Guards { - private static final Logger LOG = Logger - .getLogger(Guards.class.getName(), "jdk.internal.dynalink.support.messages"); - - private Guards() { - } - - /** - * Creates a guard method handle with arguments of a specified type, but with boolean return value. When invoked, it - * returns true if the first argument is of the specified class (exactly of it, not a subclass). The rest of the - * arguments will be ignored. - * - * @param clazz the class of the first argument to test for - * @param type the method type - * @return a method handle testing whether its first argument is of the specified class. - */ - @SuppressWarnings("boxing") - public static MethodHandle isOfClass(final Class clazz, final MethodType type) { - final Class declaredType = type.parameterType(0); - if(clazz == declaredType) { - LOG.log(Level.WARNING, "isOfClassGuardAlwaysTrue", new Object[] { clazz.getName(), 0, type, DynamicLinker.getLinkedCallSiteLocation() }); - return constantTrue(type); - } - if(!declaredType.isAssignableFrom(clazz)) { - LOG.log(Level.WARNING, "isOfClassGuardAlwaysFalse", new Object[] { clazz.getName(), 0, type, DynamicLinker.getLinkedCallSiteLocation() }); - return constantFalse(type); - } - return getClassBoundArgumentTest(IS_OF_CLASS, clazz, 0, type); - } - - /** - * Creates a method handle with arguments of a specified type, but with boolean return value. When invoked, it - * returns true if the first argument is instance of the specified class or its subclass). The rest of the arguments - * will be ignored. - * - * @param clazz the class of the first argument to test for - * @param type the method type - * @return a method handle testing whether its first argument is of the specified class or subclass. - */ - public static MethodHandle isInstance(final Class clazz, final MethodType type) { - return isInstance(clazz, 0, type); - } - - /** - * Creates a method handle with arguments of a specified type, but with boolean return value. When invoked, it - * returns true if the n'th argument is instance of the specified class or its subclass). The rest of the arguments - * will be ignored. - * - * @param clazz the class of the first argument to test for - * @param pos the position on the argument list to test - * @param type the method type - * @return a method handle testing whether its first argument is of the specified class or subclass. - */ - @SuppressWarnings("boxing") - public static MethodHandle isInstance(final Class clazz, final int pos, final MethodType type) { - final Class declaredType = type.parameterType(pos); - if(clazz.isAssignableFrom(declaredType)) { - LOG.log(Level.WARNING, "isInstanceGuardAlwaysTrue", new Object[] { clazz.getName(), pos, type, DynamicLinker.getLinkedCallSiteLocation() }); - return constantTrue(type); - } - if(!declaredType.isAssignableFrom(clazz)) { - LOG.log(Level.WARNING, "isInstanceGuardAlwaysFalse", new Object[] { clazz.getName(), pos, type, DynamicLinker.getLinkedCallSiteLocation() }); - return constantFalse(type); - } - return getClassBoundArgumentTest(IS_INSTANCE, clazz, pos, type); - } - - /** - * Creates a method handle that returns true if the argument in the specified position is a Java array. - * - * @param pos the position in the argument lit - * @param type the method type of the handle - * @return a method handle that returns true if the argument in the specified position is a Java array; the rest of - * the arguments are ignored. - */ - @SuppressWarnings("boxing") - public static MethodHandle isArray(final int pos, final MethodType type) { - final Class declaredType = type.parameterType(pos); - if(declaredType.isArray()) { - LOG.log(Level.WARNING, "isArrayGuardAlwaysTrue", new Object[] { pos, type, DynamicLinker.getLinkedCallSiteLocation() }); - return constantTrue(type); - } - if(!declaredType.isAssignableFrom(Object[].class)) { - LOG.log(Level.WARNING, "isArrayGuardAlwaysFalse", new Object[] { pos, type, DynamicLinker.getLinkedCallSiteLocation() }); - return constantFalse(type); - } - return asType(IS_ARRAY, pos, type); - } - - /** - * Return true if it is safe to strongly reference a class from the referred class loader from a class associated - * with the referring class loader without risking a class loader memory leak. - * - * @param referrerLoader the referrer class loader - * @param referredLoader the referred class loader - * @return true if it is safe to strongly reference the class - */ - public static boolean canReferenceDirectly(final ClassLoader referrerLoader, final ClassLoader referredLoader) { - if(referredLoader == null) { - // Can always refer directly to a system class - return true; - } - if(referrerLoader == null) { - // System classes can't refer directly to any non-system class - return false; - } - // Otherwise, can only refer directly to classes residing in same or - // parent class loader. - - ClassLoader referrer = referrerLoader; - do { - if(referrer == referredLoader) { - return true; - } - referrer = referrer.getParent(); - } while(referrer != null); - return false; - } - - private static MethodHandle getClassBoundArgumentTest(final MethodHandle test, final Class clazz, final int pos, final MethodType type) { - // Bind the class to the first argument of the test - return asType(test.bindTo(clazz), pos, type); - } - - /** - * Takes a guard-test method handle, and adapts it to the requested type, returning a boolean. Only applies - * conversions as per {@link MethodHandle#asType(MethodType)}. - * @param test the test method handle - * @param type the type to adapt the method handle to - * @return the adapted method handle - */ - public static MethodHandle asType(final MethodHandle test, final MethodType type) { - return test.asType(getTestType(test, type)); - } - - /** - * Takes a guard-test method handle, and adapts it to the requested type, returning a boolean. Applies the passed - * {@link LinkerServices} object's {@link LinkerServices#asType(MethodHandle, MethodType)}. - * @param linkerServices the linker services to use for type conversions - * @param test the test method handle - * @param type the type to adapt the method handle to - * @return the adapted method handle - */ - public static MethodHandle asType(final LinkerServices linkerServices, final MethodHandle test, final MethodType type) { - return linkerServices.asType(test, getTestType(test, type)); - } - - private static MethodType getTestType(final MethodHandle test, final MethodType type) { - return type.dropParameterTypes(test.type().parameterCount(), - type.parameterCount()).changeReturnType(boolean.class); - } - - private static MethodHandle asType(final MethodHandle test, final int pos, final MethodType type) { - assert test != null; - assert type != null; - assert type.parameterCount() > 0; - assert pos >= 0 && pos < type.parameterCount(); - assert test.type().parameterCount() == 1; - assert test.type().returnType() == Boolean.TYPE; - return MethodHandles.permuteArguments(test.asType(test.type().changeParameterType(0, type.parameterType(pos))), - type.changeReturnType(Boolean.TYPE), new int[] { pos }); - } - - private static final MethodHandle IS_INSTANCE = Lookup.PUBLIC.findVirtual(Class.class, "isInstance", - MethodType.methodType(Boolean.TYPE, Object.class)); - - private static final MethodHandle IS_OF_CLASS; - private static final MethodHandle IS_ARRAY; - private static final MethodHandle IS_IDENTICAL; - private static final MethodHandle IS_NULL; - private static final MethodHandle IS_NOT_NULL; - - static { - final Lookup lookup = new Lookup(MethodHandles.lookup()); - - IS_OF_CLASS = lookup.findOwnStatic("isOfClass", Boolean.TYPE, Class.class, Object.class); - IS_ARRAY = lookup.findOwnStatic("isArray", Boolean.TYPE, Object.class); - IS_IDENTICAL = lookup.findOwnStatic("isIdentical", Boolean.TYPE, Object.class, Object.class); - IS_NULL = lookup.findOwnStatic("isNull", Boolean.TYPE, Object.class); - IS_NOT_NULL = lookup.findOwnStatic("isNotNull", Boolean.TYPE, Object.class); - } - - /** - * Creates a guard method that tests its only argument for being of an exact particular class. - * @param clazz the class to test for. - * @return the desired guard method. - */ - public static MethodHandle getClassGuard(final Class clazz) { - return IS_OF_CLASS.bindTo(clazz); - } - - /** - * Creates a guard method that tests its only argument for being an instance of a particular class. - * @param clazz the class to test for. - * @return the desired guard method. - */ - public static MethodHandle getInstanceOfGuard(final Class clazz) { - return IS_INSTANCE.bindTo(clazz); - } - - /** - * Creates a guard method that tests its only argument for being referentially identical to another object - * @param obj the object used as referential identity test - * @return the desired guard method. - */ - public static MethodHandle getIdentityGuard(final Object obj) { - return IS_IDENTICAL.bindTo(obj); - } - - /** - * Returns a guard that tests whether the first argument is null. - * @return a guard that tests whether the first argument is null. - */ - public static MethodHandle isNull() { - return IS_NULL; - } - - /** - * Returns a guard that tests whether the first argument is not null. - * @return a guard that tests whether the first argument is not null. - */ - public static MethodHandle isNotNull() { - return IS_NOT_NULL; - } - - @SuppressWarnings("unused") - private static boolean isNull(final Object obj) { - return obj == null; - } - - @SuppressWarnings("unused") - private static boolean isNotNull(final Object obj) { - return obj != null; - } - - @SuppressWarnings("unused") - private static boolean isArray(final Object o) { - return o != null && o.getClass().isArray(); - } - - @SuppressWarnings("unused") - private static boolean isOfClass(final Class c, final Object o) { - return o != null && o.getClass() == c; - } - - @SuppressWarnings("unused") - private static boolean isIdentical(final Object o1, final Object o2) { - return o1 == o2; - } - - private static MethodHandle constantTrue(final MethodType type) { - return constantBoolean(Boolean.TRUE, type); - } - - private static MethodHandle constantFalse(final MethodType type) { - return constantBoolean(Boolean.FALSE, type); - } - - private static MethodHandle constantBoolean(final Boolean value, final MethodType type) { - return MethodHandles.permuteArguments(MethodHandles.constant(Boolean.TYPE, value), - type.changeReturnType(Boolean.TYPE)); - } -} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/Lookup.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/Lookup.java Mon Oct 19 22:36:03 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,401 +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.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -/** - * A wrapper around {@link java.lang.invoke.MethodHandles.Lookup} that masks - * checked exceptions. It is useful in those cases when you're looking up - * methods within your own codebase (therefore it is an error if they are not - * present). - */ -public class Lookup { - private final MethodHandles.Lookup lookup; - - /** - * Creates a new instance, bound to an instance of - * {@link java.lang.invoke.MethodHandles.Lookup}. - * - * @param lookup the {@link java.lang.invoke.MethodHandles.Lookup} it delegates to. - */ - public Lookup(final MethodHandles.Lookup lookup) { - this.lookup = lookup; - } - - /** - * A canonical Lookup object that wraps {@link MethodHandles#publicLookup()}. - */ - public static final Lookup PUBLIC = new Lookup(MethodHandles.publicLookup()); - - /** - * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)}, - * converting any encountered {@link IllegalAccessException} into an - * {@link IllegalAccessError}. - * - * @param m the method to unreflect - * @return the unreflected method handle. - * @throws IllegalAccessError if the method is inaccessible. - */ - public MethodHandle unreflect(final Method m) { - return unreflect(lookup, m); - } - - /** - * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)}, - * converting any encountered {@link IllegalAccessException} into an - * {@link IllegalAccessError}. - * - * @param lookup the lookup used to unreflect - * @param m the method to unreflect - * @return the unreflected method handle. - * @throws IllegalAccessError if the method is inaccessible. - */ - public static MethodHandle unreflect(final MethodHandles.Lookup lookup, final Method m) { - try { - return lookup.unreflect(m); - } catch(final IllegalAccessException e) { - final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect method " + m); - ee.initCause(e); - throw ee; - } - } - - /** - * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectGetter(Field)}, - * converting any encountered {@link IllegalAccessException} into an {@link IllegalAccessError}. - * - * @param f the field for which a getter is unreflected - * @return the unreflected field getter handle. - * @throws IllegalAccessError if the getter is inaccessible. - */ - public MethodHandle unreflectGetter(final Field f) { - try { - return lookup.unreflectGetter(f); - } catch(final IllegalAccessException e) { - final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect getter for field " + f); - ee.initCause(e); - throw ee; - } - } - - /** - * Performs a {@link java.lang.invoke.MethodHandles.Lookup#findGetter(Class, String, Class)}, - * converting any encountered {@link IllegalAccessException} into an - * {@link IllegalAccessError} and {@link NoSuchFieldException} into a - * {@link NoSuchFieldError}. - * - * @param refc the class declaring the field - * @param name the name of the field - * @param type the type of the field - * @return the unreflected field getter handle. - * @throws IllegalAccessError if the field is inaccessible. - * @throws NoSuchFieldError if the field does not exist. - */ - public MethodHandle findGetter(final Classrefc, final String name, final Class type) { - try { - return lookup.findGetter(refc, name, type); - } catch(final IllegalAccessException e) { - final IllegalAccessError ee = new IllegalAccessError("Failed to access getter for field " + refc.getName() + - "." + name + " of type " + type.getName()); - ee.initCause(e); - throw ee; - } catch(final NoSuchFieldException e) { - final NoSuchFieldError ee = new NoSuchFieldError("Failed to find getter for field " + refc.getName() + - "." + name + " of type " + type.getName()); - ee.initCause(e); - throw ee; - } - } - - /** - * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectSetter(Field)}, - * converting any encountered {@link IllegalAccessException} into an - * {@link IllegalAccessError}. - * - * @param f the field for which a setter is unreflected - * @return the unreflected field setter handle. - * @throws IllegalAccessError if the field is inaccessible. - * @throws NoSuchFieldError if the field does not exist. - */ - public MethodHandle unreflectSetter(final Field f) { - try { - return lookup.unreflectSetter(f); - } catch(final IllegalAccessException e) { - final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect setter for field " + f); - ee.initCause(e); - throw ee; - } - } - - /** - * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor)}, - * converting any encountered {@link IllegalAccessException} into an - * {@link IllegalAccessError}. - * - * @param c the constructor to unreflect - * @return the unreflected constructor handle. - * @throws IllegalAccessError if the constructor is inaccessible. - */ - public MethodHandle unreflectConstructor(final Constructor c) { - return unreflectConstructor(lookup, c); - } - - /** - * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor)}, - * converting any encountered {@link IllegalAccessException} into an - * {@link IllegalAccessError}. - * - * @param lookup the lookup used to unreflect - * @param c the constructor to unreflect - * @return the unreflected constructor handle. - * @throws IllegalAccessError if the constructor is inaccessible. - */ - public static MethodHandle unreflectConstructor(final MethodHandles.Lookup lookup, final Constructor c) { - try { - return lookup.unreflectConstructor(c); - } catch(final IllegalAccessException e) { - final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect constructor " + c); - ee.initCause(e); - throw ee; - } - } - - /** - * Performs a {@link java.lang.invoke.MethodHandles.Lookup#findSpecial(Class, String, MethodType, Class)} - * on the underlying lookup. Converts any encountered - * {@link IllegalAccessException} into an {@link IllegalAccessError} and - * {@link NoSuchMethodException} into a {@link NoSuchMethodError}. - * - * @param declaringClass class declaring the method - * @param name the name of the method - * @param type the type of the method - * @return a method handle for the method - * @throws IllegalAccessError if the method is inaccessible. - * @throws NoSuchMethodError if the method does not exist. - */ - public MethodHandle findSpecial(final Class declaringClass, final String name, final MethodType type) { - try { - return lookup.findSpecial(declaringClass, name, type, declaringClass); - } catch(final IllegalAccessException e) { - final IllegalAccessError ee = new IllegalAccessError("Failed to access special method " + methodDescription( - declaringClass, name, type)); - ee.initCause(e); - throw ee; - } catch(final NoSuchMethodException e) { - final NoSuchMethodError ee = new NoSuchMethodError("Failed to find special method " + methodDescription( - declaringClass, name, type)); - ee.initCause(e); - throw ee; - } - } - - private static String methodDescription(final Class declaringClass, final String name, final MethodType type) { - return declaringClass.getName() + "#" + name + type; - } - - /** - * Performs a {@link java.lang.invoke.MethodHandles.Lookup#findStatic(Class, String, MethodType)} - * on the underlying lookup. Converts any encountered - * {@link IllegalAccessException} into an {@link IllegalAccessError} and - * {@link NoSuchMethodException} into a {@link NoSuchMethodError}. - * - * @param declaringClass class declaring the method - * @param name the name of the method - * @param type the type of the method - * @return a method handle for the method - * @throws IllegalAccessError if the method is inaccessible. - * @throws NoSuchMethodError if the method does not exist. - */ - public MethodHandle findStatic(final Class declaringClass, final String name, final MethodType type) { - try { - return lookup.findStatic(declaringClass, name, type); - } catch(final IllegalAccessException e) { - final IllegalAccessError ee = new IllegalAccessError("Failed to access static method " + methodDescription( - declaringClass, name, type)); - ee.initCause(e); - throw ee; - } catch(final NoSuchMethodException e) { - final NoSuchMethodError ee = new NoSuchMethodError("Failed to find static method " + methodDescription( - declaringClass, name, type)); - ee.initCause(e); - throw ee; - } - } - - /** - * Performs a {@link java.lang.invoke.MethodHandles.Lookup#findVirtual(Class, String, MethodType)} - * on the underlying lookup. Converts any encountered - * {@link IllegalAccessException} into an {@link IllegalAccessError} and - * {@link NoSuchMethodException} into a {@link NoSuchMethodError}. - * - * @param declaringClass class declaring the method - * @param name the name of the method - * @param type the type of the method - * @return a method handle for the method - * @throws IllegalAccessError if the method is inaccessible. - * @throws NoSuchMethodError if the method does not exist. - */ - public MethodHandle findVirtual(final Class declaringClass, final String name, final MethodType type) { - try { - return lookup.findVirtual(declaringClass, name, type); - } catch(final IllegalAccessException e) { - final IllegalAccessError ee = new IllegalAccessError("Failed to access virtual method " + methodDescription( - declaringClass, name, type)); - ee.initCause(e); - throw ee; - } catch(final NoSuchMethodException e) { - final NoSuchMethodError ee = new NoSuchMethodError("Failed to find virtual method " + methodDescription( - declaringClass, name, type)); - ee.initCause(e); - throw ee; - } - } - - /** - * Given a lookup, finds using {@link #findSpecial(Class, String, MethodType)} - * a method on that lookup's class. Useful in classes' code for convenient - * linking to their own privates. - * @param lookup the lookup for the class - * @param name the name of the method - * @param rtype the return type of the method - * @param ptypes the parameter types of the method - * @return the method handle for the method - */ - public static MethodHandle findOwnSpecial(final MethodHandles.Lookup lookup, final String name, final Class rtype, final Class... ptypes) { - return new Lookup(lookup).findOwnSpecial(name, rtype, ptypes); - } - - - /** - * Finds using {@link #findSpecial(Class, String, MethodType)} a method on - * that lookup's class. Useful in classes' code for convenient linking to - * their own privates. It's also more convenient than {@code findSpecial} - * in that you can just list the parameter types, and don't have to specify - * lookup class. - * @param name the name of the method - * @param rtype the return type of the method - * @param ptypes the parameter types of the method - * @return the method handle for the method - */ - public MethodHandle findOwnSpecial(final String name, final Class rtype, final Class... ptypes) { - return findSpecial(lookup.lookupClass(), name, MethodType.methodType(rtype, ptypes)); - } - - /** - * Given a lookup, finds using {@link #findStatic(Class, String, MethodType)} - * a method on that lookup's class. Useful in classes' code for convenient - * linking to their own privates. It's easier to use than {@code findStatic} - * in that you can just list the parameter types, and don't have to specify - * lookup class. - * @param lookup the lookup for the class - * @param name the name of the method - * @param rtype the return type of the method - * @param ptypes the parameter types of the method - * @return the method handle for the method - */ - public static MethodHandle findOwnStatic(final MethodHandles.Lookup lookup, final String name, final Class rtype, final Class... ptypes) { - return new Lookup(lookup).findOwnStatic(name, rtype, ptypes); - } - - /** - * Finds using {@link #findStatic(Class, String, MethodType)} a method on - * that lookup's class. Useful in classes' code for convenient linking to - * their own privates. It's easier to use than {@code findStatic} - * in that you can just list the parameter types, and don't have to specify - * lookup class. - * @param name the name of the method - * @param rtype the return type of the method - * @param ptypes the parameter types of the method - * @return the method handle for the method - */ - public MethodHandle findOwnStatic(final String name, final Class rtype, final Class... ptypes) { - return findStatic(lookup.lookupClass(), name, MethodType.methodType(rtype, ptypes)); - } -} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/SimpleLinkRequest.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/SimpleLinkRequest.java Mon Oct 19 22:36:03 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,136 +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.CallSiteDescriptor; -import jdk.internal.dynalink.linker.LinkRequest; - -/** - * Default simple implementation of {@link LinkRequest}. - */ -public class SimpleLinkRequest implements LinkRequest { - - private final CallSiteDescriptor callSiteDescriptor; - private final Object[] arguments; - private final boolean callSiteUnstable; - - /** - * Creates a new link request. - * - * @param callSiteDescriptor the descriptor for the call site being linked. - * @param callSiteUnstable true if the call site being linked is considered - * unstable. - * @param arguments the arguments for the invocation - */ - public SimpleLinkRequest(final CallSiteDescriptor callSiteDescriptor, final boolean callSiteUnstable, final Object... arguments) { - this.callSiteDescriptor = callSiteDescriptor; - this.callSiteUnstable = callSiteUnstable; - this.arguments = arguments; - } - - @Override - public Object[] getArguments() { - return arguments != null ? arguments.clone() : null; - } - - @Override - public Object getReceiver() { - return arguments != null && arguments.length > 0 ? arguments[0] : null; - } - - @Override - public CallSiteDescriptor getCallSiteDescriptor() { - return callSiteDescriptor; - } - - @Override - public boolean isCallSiteUnstable() { - return callSiteUnstable; - } - - @Override - public LinkRequest replaceArguments(final CallSiteDescriptor newCallSiteDescriptor, final Object[] newArguments) { - return new SimpleLinkRequest(newCallSiteDescriptor, callSiteUnstable, newArguments); - } -} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/SimpleRelinkableCallSite.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/SimpleRelinkableCallSite.java Tue Oct 20 23:33:18 2015 +0200 @@ -0,0 +1,115 @@ +/* + * 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.MethodHandle; +import jdk.internal.dynalink.CallSiteDescriptor; +import jdk.internal.dynalink.DynamicLinker; +import jdk.internal.dynalink.linker.GuardedInvocation; + +/** + * A relinkable call site that implements monomorphic inline caching strategy, + * only being linked to a single {@link GuardedInvocation}. If that invocation + * is invalidated, it will throw it away and ask its associated + * {@link DynamicLinker} to relink it. + */ +public class SimpleRelinkableCallSite extends AbstractRelinkableCallSite { + /** + * Creates a new call site with monomorphic inline caching strategy. + * @param descriptor the descriptor for this call site + */ + public SimpleRelinkableCallSite(final CallSiteDescriptor descriptor) { + super(descriptor); + } + + @Override + public void relink(final GuardedInvocation guardedInvocation, final MethodHandle relinkAndInvoke) { + setTarget(guardedInvocation.compose(relinkAndInvoke)); + } + + @Override + public void resetAndRelink(final GuardedInvocation guardedInvocation, final MethodHandle relinkAndInvoke) { + relink(guardedInvocation, relinkAndInvoke); + } +} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/TypeUtilities.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/TypeUtilities.java Mon Oct 19 22:36:03 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,530 +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.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.IdentityHashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Various static utility methods for testing type relationships. - */ -public class TypeUtilities { - static final Class OBJECT_CLASS = Object.class; - - private TypeUtilities() { - } - - /** - * Given two types represented by c1 and c2, returns a type that is their most specific common supertype for - * purposes of lossless conversions. - * - * @param c1 one type - * @param c2 another type - * @return their most common superclass or superinterface for purposes of lossless conversions. If they have several - * unrelated superinterfaces as their most specific common type, or the types themselves are completely - * unrelated interfaces, {@link java.lang.Object} is returned. - */ - public static Class getCommonLosslessConversionType(final Class c1, final Class c2) { - if(c1 == c2) { - return c1; - } else if (c1 == void.class || c2 == void.class) { - return Object.class; - } else if(isConvertibleWithoutLoss(c2, c1)) { - return c1; - } else if(isConvertibleWithoutLoss(c1, c2)) { - return c2; - } else if(c1.isPrimitive() && c2.isPrimitive()) { - if((c1 == byte.class && c2 == char.class) || (c1 == char.class && c2 == byte.class)) { - // byte + char = int - return int.class; - } else if((c1 == short.class && c2 == char.class) || (c1 == char.class && c2 == short.class)) { - // short + char = int - return int.class; - } else if((c1 == int.class && c2 == float.class) || (c1 == float.class && c2 == int.class)) { - // int + float = double - return double.class; - } - } - // For all other cases. This will handle long + (float|double) = Number case as well as boolean + anything = Object case too. - return getMostSpecificCommonTypeUnequalNonprimitives(c1, c2); - } - - private static Class getMostSpecificCommonTypeUnequalNonprimitives(final Class c1, final Class c2) { - final Class npc1 = c1.isPrimitive() ? getWrapperType(c1) : c1; - final Class npc2 = c2.isPrimitive() ? getWrapperType(c2) : c2; - final Set> a1 = getAssignables(npc1, npc2); - final Set> a2 = getAssignables(npc2, npc1); - a1.retainAll(a2); - if(a1.isEmpty()) { - // Can happen when at least one of the arguments is an interface, - // as they don't have Object at the root of their hierarchy. - return Object.class; - } - // Gather maximally specific elements. Yes, there can be more than one - // thank to interfaces. I.e., if you call this method for String.class - // and Number.class, you'll have Comparable, Serializable, and Object - // as maximal elements. - final List> max = new ArrayList<>(); - outer: for(final Class clazz: a1) { - for(final Iterator> maxiter = max.iterator(); maxiter.hasNext();) { - final Class maxClazz = maxiter.next(); - if(isSubtype(maxClazz, clazz)) { - // It can't be maximal, if there's already a more specific - // maximal than it. - continue outer; - } - if(isSubtype(clazz, maxClazz)) { - // If it's more specific than a currently maximal element, - // that currently maximal is no longer a maximal. - maxiter.remove(); - } - } - // If we get here, no current maximal is more specific than the - // current class, so it is considered maximal as well - max.add(clazz); - } - if(max.size() > 1) { - return Object.class; - } - return max.get(0); - } - - private static Set> getAssignables(final Class c1, final Class c2) { - final Set> s = new HashSet<>(); - collectAssignables(c1, c2, s); - return s; - } - - private static void collectAssignables(final Class c1, final Class c2, final Set> s) { - if(c1.isAssignableFrom(c2)) { - s.add(c1); - } - final Class sc = c1.getSuperclass(); - if(sc != null) { - collectAssignables(sc, c2, s); - } - final Class[] itf = c1.getInterfaces(); - for(int i = 0; i < itf.length; ++i) { - collectAssignables(itf[i], c2, s); - } - } - - private static final Map, Class> WRAPPER_TYPES = createWrapperTypes(); - private static final Map, Class> PRIMITIVE_TYPES = invertMap(WRAPPER_TYPES); - private static final Map> PRIMITIVE_TYPES_BY_NAME = createClassNameMapping(WRAPPER_TYPES.keySet()); - - private static Map, Class> createWrapperTypes() { - final Map, Class> wrapperTypes = new IdentityHashMap<>(8); - wrapperTypes.put(Boolean.TYPE, Boolean.class); - wrapperTypes.put(Byte.TYPE, Byte.class); - wrapperTypes.put(Character.TYPE, Character.class); - wrapperTypes.put(Short.TYPE, Short.class); - wrapperTypes.put(Integer.TYPE, Integer.class); - wrapperTypes.put(Long.TYPE, Long.class); - wrapperTypes.put(Float.TYPE, Float.class); - wrapperTypes.put(Double.TYPE, Double.class); - return Collections.unmodifiableMap(wrapperTypes); - } - - private static Map> createClassNameMapping(final Collection> classes) { - final Map> map = new HashMap<>(); - for(final Class clazz: classes) { - map.put(clazz.getName(), clazz); - } - return map; - } - - private static Map invertMap(final Map map) { - final Map inverted = new IdentityHashMap<>(map.size()); - for(final Map.Entry entry: map.entrySet()) { - inverted.put(entry.getValue(), entry.getKey()); - } - return Collections.unmodifiableMap(inverted); - } - - /** - * Determines whether one type can be converted to another type using a method invocation conversion, as per JLS 5.3 - * "Method Invocation Conversion". This is basically all conversions allowed by subtyping (see - * {@link #isSubtype(Class, Class)}) as well as boxing conversion (JLS 5.1.7) optionally followed by widening - * reference conversion and unboxing conversion (JLS 5.1.8) optionally followed by widening primitive conversion. - * - * @param sourceType the type being converted from (call site type for parameter types, method type for return types) - * @param targetType the parameter type being converted to (method type for parameter types, call site type for return types) - * @return true if source type is method invocation convertible to target type. - */ - public static boolean isMethodInvocationConvertible(final Class sourceType, final Class targetType) { - if(targetType.isAssignableFrom(sourceType)) { - return true; - } - if(sourceType.isPrimitive()) { - if(targetType.isPrimitive()) { - return isProperPrimitiveSubtype(sourceType, targetType); - } - // Boxing + widening reference conversion - assert WRAPPER_TYPES.get(sourceType) != null : sourceType.getName(); - return targetType.isAssignableFrom(WRAPPER_TYPES.get(sourceType)); - } - if(targetType.isPrimitive()) { - final Class unboxedCallSiteType = PRIMITIVE_TYPES.get(sourceType); - return unboxedCallSiteType != null - && (unboxedCallSiteType == targetType || isProperPrimitiveSubtype(unboxedCallSiteType, targetType)); - } - return false; - } - - /** - * Determines whether a type can be converted to another without losing any precision. As a special case, - * void is considered convertible only to Object and void, while anything can be converted to void. This - * is because a target type of void means we don't care about the value, so the conversion is always - * permissible. - * - * @param sourceType the source type - * @param targetType the target type - * @return true if lossless conversion is possible - */ - public static boolean isConvertibleWithoutLoss(final Class sourceType, final Class targetType) { - if(targetType.isAssignableFrom(sourceType) || targetType == void.class) { - return true; - } - if(sourceType.isPrimitive()) { - if(sourceType == void.class) { - // Void should be losslessly representable by Object, either as null or as a custom value that - // can be set with DynamicLinkerFactory.setAutoConversionStrategy. - return targetType == Object.class; - } - if(targetType.isPrimitive()) { - return isProperPrimitiveLosslessSubtype(sourceType, targetType); - } - // Boxing + widening reference conversion - assert WRAPPER_TYPES.get(sourceType) != null : sourceType.getName(); - return targetType.isAssignableFrom(WRAPPER_TYPES.get(sourceType)); - } - // Can't convert from any non-primitive type to any primitive type without data loss because of null. - // Also, can't convert non-assignable reference types. - return false; - } - - /** - * Determines whether one type can be potentially converted to another type at runtime. Allows a conversion between - * any subtype and supertype in either direction, and also allows a conversion between any two primitive types, as - * well as between any primitive type and any reference type that can hold a boxed primitive. - * - * @param callSiteType the parameter type at the call site - * @param methodType the parameter type in the method declaration - * @return true if callSiteType is potentially convertible to the methodType. - */ - public static boolean isPotentiallyConvertible(final Class callSiteType, final Class methodType) { - // Widening or narrowing reference conversion - if(areAssignable(callSiteType, methodType)) { - return true; - } - if(callSiteType.isPrimitive()) { - // Allow any conversion among primitives, as well as from any - // primitive to any type that can receive a boxed primitive. - // TODO: narrow this a bit, i.e. allow, say, boolean to Character? - // MethodHandles.convertArguments() allows it, so we might need to - // too. - return methodType.isPrimitive() || isAssignableFromBoxedPrimitive(methodType); - } - if(methodType.isPrimitive()) { - // Allow conversion from any reference type that can contain a - // boxed primitive to any primitive. - // TODO: narrow this a bit too? - return isAssignableFromBoxedPrimitive(callSiteType); - } - return false; - } - - /** - * Returns true if either of the types is assignable from the other. - * @param c1 one of the types - * @param c2 another one of the types - * @return true if either c1 is assignable from c2 or c2 is assignable from c1. - */ - public static boolean areAssignable(final Class c1, final Class c2) { - return c1.isAssignableFrom(c2) || c2.isAssignableFrom(c1); - } - - /** - * Determines whether one type is a subtype of another type, as per JLS 4.10 "Subtyping". Note: this is not strict - * or proper subtype, therefore true is also returned for identical types; to be completely precise, it allows - * identity conversion (JLS 5.1.1), widening primitive conversion (JLS 5.1.2) and widening reference conversion (JLS - * 5.1.5). - * - * @param subType the supposed subtype - * @param superType the supposed supertype of the subtype - * @return true if subType can be converted by identity conversion, widening primitive conversion, or widening - * reference conversion to superType. - */ - public static boolean isSubtype(final Class subType, final Class superType) { - // Covers both JLS 4.10.2 "Subtyping among Class and Interface Types" - // and JLS 4.10.3 "Subtyping among Array Types", as well as primitive - // type identity. - if(superType.isAssignableFrom(subType)) { - return true; - } - // JLS 4.10.1 "Subtyping among Primitive Types". Note we don't test for - // identity, as identical types were taken care of in the - // isAssignableFrom test. As per 4.10.1, the supertype relation is as - // follows: - // double > float - // float > long - // long > int - // int > short - // int > char - // short > byte - if(superType.isPrimitive() && subType.isPrimitive()) { - return isProperPrimitiveSubtype(subType, superType); - } - return false; - } - - /** - * Returns true if a supposed primitive subtype is a proper subtype ( meaning, subtype and not identical) of the - * supposed primitive supertype - * - * @param subType the supposed subtype - * @param superType the supposed supertype - * @return true if subType is a proper (not identical to) primitive subtype of the superType - */ - private static boolean isProperPrimitiveSubtype(final Class subType, final Class superType) { - if(superType == boolean.class || subType == boolean.class) { - return false; - } - if(subType == byte.class) { - return superType != char.class; - } - if(subType == char.class) { - return superType != short.class && superType != byte.class; - } - if(subType == short.class) { - return superType != char.class && superType != byte.class; - } - if(subType == int.class) { - return superType == long.class || superType == float.class || superType == double.class; - } - if(subType == long.class) { - return superType == float.class || superType == double.class; - } - if(subType == float.class) { - return superType == double.class; - } - return false; - } - - /** - * Similar to {@link #isProperPrimitiveSubtype(Class, Class)}, except it disallows conversions from int and long to - * float, and from long to double, as those can lose precision. It also disallows conversion from and to char and - * anything else (similar to boolean) as char is not meant to be an arithmetic type. - * @param subType the supposed subtype - * @param superType the supposed supertype - * @return true if subType is a proper (not identical to) primitive subtype of the superType that can be represented - * by the supertype without no precision loss. - */ - private static boolean isProperPrimitiveLosslessSubtype(final Class subType, final Class superType) { - if(superType == boolean.class || subType == boolean.class) { - return false; - } - if(superType == char.class || subType == char.class) { - return false; - } - if(subType == byte.class) { - return true; - } - if(subType == short.class) { - return superType != byte.class; - } - if(subType == int.class) { - return superType == long.class || superType == double.class; - } - if(subType == float.class) { - return superType == double.class; - } - return false; - } - - private static final Map, Class> WRAPPER_TO_PRIMITIVE_TYPES = createWrapperToPrimitiveTypes(); - - private static Map, Class> createWrapperToPrimitiveTypes() { - final Map, Class> classes = new IdentityHashMap<>(); - classes.put(Void.class, Void.TYPE); - classes.put(Boolean.class, Boolean.TYPE); - classes.put(Byte.class, Byte.TYPE); - classes.put(Character.class, Character.TYPE); - classes.put(Short.class, Short.TYPE); - classes.put(Integer.class, Integer.TYPE); - classes.put(Long.class, Long.TYPE); - classes.put(Float.class, Float.TYPE); - classes.put(Double.class, Double.TYPE); - return classes; - } - - private static final Set> PRIMITIVE_WRAPPER_TYPES = createPrimitiveWrapperTypes(); - - private static Set> createPrimitiveWrapperTypes() { - final Map, Class> classes = new IdentityHashMap<>(); - addClassHierarchy(classes, Boolean.class); - addClassHierarchy(classes, Byte.class); - addClassHierarchy(classes, Character.class); - addClassHierarchy(classes, Short.class); - addClassHierarchy(classes, Integer.class); - addClassHierarchy(classes, Long.class); - addClassHierarchy(classes, Float.class); - addClassHierarchy(classes, Double.class); - return classes.keySet(); - } - - private static void addClassHierarchy(final Map, Class> map, final Class clazz) { - if(clazz == null) { - return; - } - map.put(clazz, clazz); - addClassHierarchy(map, clazz.getSuperclass()); - for(final Class itf: clazz.getInterfaces()) { - addClassHierarchy(map, itf); - } - } - - /** - * Returns true if the class can be assigned from any boxed primitive. - * - * @param clazz the class - * @return true if the class can be assigned from any boxed primitive. Basically, it is true if the class is any - * primitive wrapper class, or a superclass or superinterface of any primitive wrapper class. - */ - private static boolean isAssignableFromBoxedPrimitive(final Class clazz) { - return PRIMITIVE_WRAPPER_TYPES.contains(clazz); - } - - /** - * Given a name of a primitive type (except "void"), returns the class representing it. I.e. when invoked with - * "int", returns {@link Integer#TYPE}. - * @param name the name of the primitive type - * @return the class representing the primitive type, or null if the name does not correspond to a primitive type - * or is "void". - */ - public static Class getPrimitiveTypeByName(final String name) { - return PRIMITIVE_TYPES_BY_NAME.get(name); - } - - /** - * When passed a class representing a wrapper for a primitive type, returns the class representing the corresponding - * primitive type. I.e. calling it with {@code Integer.class} will return {@code Integer.TYPE}. If passed a class - * that is not a wrapper for primitive type, returns null. - * @param wrapperType the class object representing a wrapper for a primitive type - * @return the class object representing the primitive type, or null if the passed class is not a primitive wrapper. - */ - public static Class getPrimitiveType(final Class wrapperType) { - return WRAPPER_TO_PRIMITIVE_TYPES.get(wrapperType); - } - - - /** - * When passed a class representing a primitive type, returns the class representing the corresponding - * wrapper type. I.e. calling it with {@code int.class} will return {@code Integer.class}. If passed a class - * that is not a primitive type, returns null. - * @param primitiveType the class object representing a primitive type - * @return the class object representing the wrapper type, or null if the passed class is not a primitive. - */ - public static Class getWrapperType(final Class primitiveType) { - return WRAPPER_TYPES.get(primitiveType); - } - - /** - * Returns true if the passed type is a wrapper for a primitive type. - * @param type the examined type - * @return true if the passed type is a wrapper for a primitive type. - */ - public static boolean isWrapperType(final Class type) { - return PRIMITIVE_TYPES.containsKey(type); - } -} diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFunction.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFunction.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFunction.java Tue Oct 20 23:33:18 2015 +0200 @@ -33,7 +33,7 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.util.List; -import jdk.internal.dynalink.support.Lookup; +import jdk.internal.dynalink.linker.support.Lookup; import jdk.nashorn.api.scripting.JSObject; import jdk.nashorn.internal.objects.annotations.Attribute; import jdk.nashorn.internal.objects.annotations.Constructor; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJava.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJava.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeJava.java Tue Oct 20 23:33:18 2015 +0200 @@ -39,7 +39,7 @@ import java.util.Queue; import jdk.internal.dynalink.beans.BeansLinker; import jdk.internal.dynalink.beans.StaticClass; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.TypeUtilities; import jdk.nashorn.api.scripting.JSObject; import jdk.nashorn.api.scripting.ScriptObjectMirror; import jdk.nashorn.internal.objects.annotations.Attribute; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeObject.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeObject.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeObject.java Tue Oct 20 23:33:18 2015 +0200 @@ -44,7 +44,7 @@ import jdk.internal.dynalink.linker.GuardedInvocation; import jdk.internal.dynalink.linker.GuardingDynamicLinker; import jdk.internal.dynalink.linker.LinkRequest; -import jdk.internal.dynalink.support.SimpleLinkRequest; +import jdk.internal.dynalink.linker.support.SimpleLinkRequest; import jdk.nashorn.api.scripting.ScriptObjectMirror; import jdk.nashorn.internal.lookup.Lookup; import jdk.nashorn.internal.objects.annotations.Attribute; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/NativeJavaPackage.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/NativeJavaPackage.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/NativeJavaPackage.java Tue Oct 20 23:33:18 2015 +0200 @@ -36,7 +36,7 @@ import jdk.internal.dynalink.beans.StaticClass; import jdk.internal.dynalink.linker.GuardedInvocation; import jdk.internal.dynalink.linker.LinkRequest; -import jdk.internal.dynalink.support.Guards; +import jdk.internal.dynalink.linker.support.Guards; import jdk.nashorn.internal.lookup.MethodHandleFactory; import jdk.nashorn.internal.lookup.MethodHandleFunctionality; import jdk.nashorn.internal.objects.annotations.Attribute; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/OptimisticReturnFilters.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/OptimisticReturnFilters.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/OptimisticReturnFilters.java Tue Oct 20 23:33:18 2015 +0200 @@ -34,7 +34,7 @@ import java.lang.invoke.MethodType; import jdk.internal.dynalink.CallSiteDescriptor; import jdk.internal.dynalink.linker.GuardedInvocation; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.TypeUtilities; import jdk.nashorn.internal.codegen.types.Type; import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunction.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunction.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunction.java Tue Oct 20 23:33:18 2015 +0200 @@ -47,7 +47,7 @@ import jdk.internal.dynalink.CallSiteDescriptor; import jdk.internal.dynalink.linker.GuardedInvocation; import jdk.internal.dynalink.linker.LinkRequest; -import jdk.internal.dynalink.support.Guards; +import jdk.internal.dynalink.linker.support.Guards; import jdk.nashorn.internal.codegen.ApplySpecialization; import jdk.nashorn.internal.codegen.Compiler; import jdk.nashorn.internal.codegen.CompilerConstants.Call; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Undefined.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Undefined.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Undefined.java Tue Oct 20 23:33:18 2015 +0200 @@ -32,7 +32,7 @@ import java.lang.invoke.MethodHandles; import jdk.internal.dynalink.CallSiteDescriptor; import jdk.internal.dynalink.linker.GuardedInvocation; -import jdk.internal.dynalink.support.Guards; +import jdk.internal.dynalink.linker.support.Guards; import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; /** diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/NumberArrayData.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/NumberArrayData.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/NumberArrayData.java Tue Oct 20 23:33:18 2015 +0200 @@ -29,10 +29,10 @@ import static jdk.nashorn.internal.lookup.Lookup.MH; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; -import jdk.internal.dynalink.support.TypeUtilities; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.util.Arrays; +import jdk.internal.dynalink.linker.support.TypeUtilities; /** * Implementation of {@link ArrayData} as soon as a double has been diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/Bootstrap.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/Bootstrap.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/Bootstrap.java Tue Oct 20 23:33:18 2015 +0200 @@ -37,14 +37,14 @@ import jdk.internal.dynalink.CallSiteDescriptor; import jdk.internal.dynalink.DynamicLinker; import jdk.internal.dynalink.DynamicLinkerFactory; -import jdk.internal.dynalink.GuardedInvocationFilter; import jdk.internal.dynalink.beans.BeansLinker; import jdk.internal.dynalink.beans.StaticClass; import jdk.internal.dynalink.linker.GuardedInvocation; +import jdk.internal.dynalink.linker.GuardedInvocationTransformer; import jdk.internal.dynalink.linker.LinkRequest; import jdk.internal.dynalink.linker.LinkerServices; import jdk.internal.dynalink.linker.MethodTypeConversionStrategy; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.TypeUtilities; import jdk.nashorn.api.scripting.JSObject; import jdk.nashorn.internal.codegen.CompilerConstants.Call; import jdk.nashorn.internal.lookup.MethodHandleFactory; @@ -102,7 +102,7 @@ new ReflectionCheckLinker()); factory.setFallbackLinkers(nashornBeansLinker, new NashornBottomLinker()); factory.setSyncOnRelink(true); - factory.setPrelinkFilter(new GuardedInvocationFilter() { + factory.setPrelinkTransformer(new GuardedInvocationTransformer() { @Override public GuardedInvocation filter(final GuardedInvocation inv, final LinkRequest request, final LinkerServices linkerServices) { final CallSiteDescriptor desc = request.getCallSiteDescriptor(); diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/BoundCallableLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/BoundCallableLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/BoundCallableLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -34,7 +34,7 @@ import jdk.internal.dynalink.linker.LinkRequest; import jdk.internal.dynalink.linker.LinkerServices; import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker; -import jdk.internal.dynalink.support.Guards; +import jdk.internal.dynalink.linker.support.Guards; /** * Links {@link BoundCallable} objects. Passes through to linker services for linking a callable (for either diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Tue Oct 20 23:33:18 2015 +0200 @@ -47,7 +47,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import jdk.internal.dynalink.beans.StaticClass; -import jdk.internal.dynalink.support.SimpleLinkRequest; +import jdk.internal.dynalink.linker.support.SimpleLinkRequest; import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.ECMAException; import jdk.nashorn.internal.runtime.ScriptFunction; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaArgumentConverters.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaArgumentConverters.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaArgumentConverters.java Tue Oct 20 23:33:18 2015 +0200 @@ -34,7 +34,7 @@ import java.lang.invoke.MethodHandles; import java.util.HashMap; import java.util.Map; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.TypeUtilities; import jdk.nashorn.internal.runtime.ConsString; import jdk.nashorn.internal.runtime.JSType; import jdk.nashorn.internal.runtime.ScriptObject; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaSuperAdapterLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaSuperAdapterLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaSuperAdapterLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -37,7 +37,7 @@ import jdk.internal.dynalink.linker.LinkRequest; import jdk.internal.dynalink.linker.LinkerServices; import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker; -import jdk.internal.dynalink.support.Lookup; +import jdk.internal.dynalink.linker.support.Lookup; import jdk.nashorn.internal.runtime.ScriptRuntime; /** diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java Tue Oct 20 23:33:18 2015 +0200 @@ -44,9 +44,9 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.LongAdder; -import jdk.internal.dynalink.ChainedCallSite; import jdk.internal.dynalink.DynamicLinker; import jdk.internal.dynalink.linker.GuardedInvocation; +import jdk.internal.dynalink.support.ChainedCallSite; import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.Debug; import jdk.nashorn.internal.runtime.ScriptObject; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornBeansLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornBeansLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornBeansLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -40,8 +40,8 @@ import jdk.internal.dynalink.linker.LinkRequest; import jdk.internal.dynalink.linker.LinkerServices; import jdk.internal.dynalink.linker.MethodHandleTransformer; -import jdk.internal.dynalink.support.DefaultInternalObjectFilter; -import jdk.internal.dynalink.support.Lookup; +import jdk.internal.dynalink.linker.support.DefaultInternalObjectFilter; +import jdk.internal.dynalink.linker.support.Lookup; import jdk.nashorn.api.scripting.ScriptUtils; import jdk.nashorn.internal.runtime.ConsString; import jdk.nashorn.internal.runtime.Context; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -43,7 +43,7 @@ import jdk.internal.dynalink.linker.GuardingTypeConverterFactory; import jdk.internal.dynalink.linker.LinkRequest; import jdk.internal.dynalink.linker.LinkerServices; -import jdk.internal.dynalink.support.Guards; +import jdk.internal.dynalink.linker.support.Guards; import jdk.nashorn.internal.codegen.types.Type; import jdk.nashorn.internal.runtime.JSType; import jdk.nashorn.internal.runtime.ScriptRuntime; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -47,8 +47,8 @@ import jdk.internal.dynalink.linker.LinkRequest; import jdk.internal.dynalink.linker.LinkerServices; import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker; -import jdk.internal.dynalink.support.Guards; -import jdk.internal.dynalink.support.Lookup; +import jdk.internal.dynalink.linker.support.Guards; +import jdk.internal.dynalink.linker.support.Lookup; import jdk.nashorn.api.scripting.JSObject; import jdk.nashorn.api.scripting.ScriptObjectMirror; import jdk.nashorn.api.scripting.ScriptUtils; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornPrimitiveLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornPrimitiveLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornPrimitiveLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -36,7 +36,7 @@ import jdk.internal.dynalink.linker.LinkRequest; import jdk.internal.dynalink.linker.LinkerServices; import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker; -import jdk.internal.dynalink.support.TypeUtilities; +import jdk.internal.dynalink.linker.support.TypeUtilities; import jdk.nashorn.internal.objects.Global; import jdk.nashorn.internal.runtime.ConsString; import jdk.nashorn.internal.runtime.JSType; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornStaticClassLinker.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornStaticClassLinker.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornStaticClassLinker.java Tue Oct 20 23:33:18 2015 +0200 @@ -34,7 +34,7 @@ import jdk.internal.dynalink.linker.LinkRequest; import jdk.internal.dynalink.linker.LinkerServices; import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker; -import jdk.internal.dynalink.support.Guards; +import jdk.internal.dynalink.linker.support.Guards; import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.ECMAErrors; diff -r 47279b2180b4 -r af3fea63e008 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java Mon Oct 19 22:36:03 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java Tue Oct 20 23:33:18 2015 +0200 @@ -35,7 +35,7 @@ import jdk.internal.dynalink.CallSiteDescriptor; import jdk.internal.dynalink.linker.GuardedInvocation; import jdk.internal.dynalink.linker.LinkRequest; -import jdk.internal.dynalink.support.Guards; +import jdk.internal.dynalink.linker.support.Guards; import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.FindProperty; import jdk.nashorn.internal.runtime.GlobalConstants;