--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/samples/jsadapter-fallthrough.js Thu Oct 15 16:50:08 2015 -0700
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ *
+ * 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 Oracle nor the names of its
+ * 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 THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS 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.
+ */
+
+// Demonstrate how to provide a default fall-through solution for adapted Java
+// objects, forwarding all calls that are not adapted.
+
+var Date = Java.type('java.time.LocalDate')
+
+function wrapDate(d) {
+ return new JSAdapter() {
+ __call__: function() {
+ // adapted (extra) methods
+ if (arguments[0] === 'yesterday') {
+ return d.minusDays(1)
+ }
+ // fall-through: forward all other, non-adapted method calls
+ var args = [d].concat(Array.prototype.slice.call(arguments, 1))
+ return Function.call.apply(d[arguments[0]], args)
+ }
+ }
+}
+
+var now = wrapDate(Date.now())
+
+print(now)
+print(now.yesterday()) // adapted
+print(now.lengthOfMonth()) // fall through to original method
+print(now.atTime(23, 42)) // arguments are passed through
+
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/CallSiteDescriptor.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/CallSiteDescriptor.java Thu Oct 15 16:50:08 2015 -0700
@@ -96,8 +96,6 @@
* guarding linkers so they aren't tempted to directly manipulate the call sites. The constructors of built-in
* {@link RelinkableCallSite} implementations all need a call site descriptor. Even if you create your own call site
* descriptors consider using {@link CallSiteDescriptorFactory#tokenizeName(String)} in your implementation.
- *
- * @author Attila Szegedi
*/
public interface CallSiteDescriptor {
/**
@@ -157,7 +155,9 @@
public MethodType getMethodType();
/**
- * Returns the lookup passed to the bootstrap method.
+ * Returns the lookup passed to the bootstrap method. If the lookup isn't the public lookup, the
+ * implementation must check the {@code RuntimePermission("dynalink.getLookup")} permission if a security
+ * manager is present.
* @return the lookup passed to the bootstrap method.
*/
public Lookup getLookup();
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ChainedCallSite.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/ChainedCallSite.java Thu Oct 15 16:50:08 2015 -0700
@@ -85,9 +85,9 @@
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
-import java.util.concurrent.atomic.AtomicReference;
import jdk.internal.dynalink.linker.GuardedInvocation;
import jdk.internal.dynalink.support.AbstractRelinkableCallSite;
import jdk.internal.dynalink.support.Lookup;
@@ -112,7 +112,14 @@
PRUNE_SWITCHPOINTS = MethodHandles.insertArguments(PRUNE, 2, false);
}
- private final AtomicReference<LinkedList<GuardedInvocation>> invocations = new AtomicReference<>();
+ /**
+ * 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.
@@ -142,10 +149,18 @@
}
private MethodHandle relinkInternal(final GuardedInvocation invocation, final MethodHandle relink, final boolean reset, final boolean removeCatches) {
- final LinkedList<GuardedInvocation> currentInvocations = invocations.get();
- @SuppressWarnings({ "unchecked", "rawtypes" })
- final LinkedList<GuardedInvocation> newInvocations =
- currentInvocations == null || reset ? new LinkedList<>() : (LinkedList)currentInvocations.clone();
+ final Object currentInvocations = invocations;
+ final LinkedList<GuardedInvocation> 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
@@ -177,12 +192,17 @@
target = inv.compose(target, pruneAndInvokeSwitchPoints, pruneAndInvokeCatches);
}
- // If nobody else updated the call site while we were rebuilding the chain, set the target to our chain. In case
- // we lost the race for multithreaded update, just do nothing. Either the other thread installed the same thing
- // we wanted to install, or otherwise, we'll be asked to relink again.
- if(invocations.compareAndSet(currentInvocations, newInvocations)) {
- setTarget(target);
+ 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;
}
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DefaultBootstrapper.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DefaultBootstrapper.java Thu Oct 15 16:50:08 2015 -0700
@@ -97,8 +97,6 @@
* and one that just uses the passed caller as the lookup scope. Using the public lookup one is advised if your language
* runtime has no concept of interacting with Java visibility scopes, as it results in a more lightweight runtime
* information.
- *
- * @author Attila Szegedi
*/
public class DefaultBootstrapper {
private static final DynamicLinker dynamicLinker = new DynamicLinkerFactory().createLinker();
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java Thu Oct 15 16:50:08 2015 -0700
@@ -147,15 +147,14 @@
* additional parameters to the bootstrap method) to them.</li>
*
* </ul>
- *
- * @author Attila Szegedi
*/
-public class DynamicLinker {
+public final class DynamicLinker {
private static final String CLASS_NAME = DynamicLinker.class.getName();
private static final String RELINK_METHOD_NAME = "relink";
private static final String INITIAL_LINK_CLASS_NAME = "java.lang.invoke.MethodHandleNatives";
private static final String INITIAL_LINK_METHOD_NAME = "linkCallSite";
+ private static final String INVOKE_PACKAGE_PREFIX = "java.lang.invoke.";
private final LinkerServices linkerServices;
private final GuardedInvocationFilter prelinkFilter;
@@ -305,26 +304,21 @@
final StackTraceElement[] trace = new Throwable().getStackTrace();
for(int i = 0; i < trace.length - 1; ++i) {
final StackTraceElement frame = trace[i];
+ // If we found any of our linking entry points on the stack...
if(isRelinkFrame(frame) || isInitialLinkFrame(frame)) {
- return trace[i + 1];
+ // ... then look for the first thing calling it that isn't j.l.invoke
+ for (int j = i + 1; j < trace.length; ++j) {
+ final StackTraceElement frame2 = trace[j];
+ if (!frame2.getClassName().startsWith(INVOKE_PACKAGE_PREFIX)) {
+ return frame2;
+ }
+ }
}
}
return null;
}
/**
- * Deprecated because of imprecise name.
- *
- * @deprecated Use {@link #getLinkedCallSiteLocation()} instead.
- *
- * @return see non-deprecated method
- */
- @Deprecated
- public static StackTraceElement getRelinkedCallSiteLocation() {
- return getLinkedCallSiteLocation();
- }
-
- /**
* Returns {@code true} if the frame represents {@code MethodHandleNatives.linkCallSite()},
* the frame immediately on top of the call site frame when the call site is
* being linked for the first time.
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java Thu Oct 15 16:50:08 2015 -0700
@@ -111,14 +111,13 @@
import jdk.internal.dynalink.support.TypeUtilities;
/**
- * A factory class for creating {@link DynamicLinker}s. The most usual dynamic linker is a linker that is a composition
- * of all {@link GuardingDynamicLinker}s known and pre-created by the caller as well as any
- * {@link AutoDiscovery automatically discovered} guarding linkers and the standard fallback {@link BeansLinker} and a
- * {@link DefaultPrelinkFilter}. See {@link DynamicLinker} documentation for tips on how to use this class.
- *
- * @author Attila Szegedi
+ * A factory class for creating {@link DynamicLinker}s. The usual dynamic linker is a linker composed of all
+ * {@link GuardingDynamicLinker}s known and pre-created by the caller as well as any
+ * {@link AutoDiscovery automatically discovered} guarding linkers and the standard fallback
+ * {@link BeansLinker} and a {@link DefaultPrelinkFilter}. See {@link DynamicLinker} documentation for tips on
+ * how to use this class.
*/
-public class DynamicLinkerFactory {
+public final class DynamicLinkerFactory {
/**
* Default value for {@link #setUnstableRelinkThreshold(int) unstable relink threshold}.
*/
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/MonomorphicCallSite.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/MonomorphicCallSite.java Thu Oct 15 16:50:08 2015 -0700
@@ -91,8 +91,6 @@
* A relinkable call site that implements monomorphic inline caching strategy. After it linked a method, it will keep it
* until either its guard evaluates to false, or its switchpoint is invalidated, at which time it will throw away the
* previous linkage, and trigger relinking with its associated {@link DynamicLinker}.
- *
- * @author Attila Szegedi
*/
public class MonomorphicCallSite extends AbstractRelinkableCallSite {
/**
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/NoSuchDynamicMethodException.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/NoSuchDynamicMethodException.java Thu Oct 15 16:50:08 2015 -0700
@@ -87,8 +87,6 @@
/**
* Thrown at the invocation if the call site can not be linked by any available {@link GuardingDynamicLinker}.
- *
- * @author Attila Szegedi
*/
public class NoSuchDynamicMethodException extends RuntimeException {
private static final long serialVersionUID = 1L;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/RelinkableCallSite.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/RelinkableCallSite.java Thu Oct 15 16:50:08 2015 -0700
@@ -96,13 +96,11 @@
* {@link ChainedCallSite} that retains a chain of already linked method handles. The reason this is defined as an
* interface instead of a concrete, albeit abstract class is that it allows independent implementations to choose
* between {@link MutableCallSite} and {@link VolatileCallSite} as they see fit.
- *
- * @author Attila Szegedi
*/
public interface RelinkableCallSite {
/**
- * Initializes the relinkable call site by setting a relink-and-invoke method handle. The call site implementation
- * is supposed to set this method handle as its target.
+ * Initializes the relinkable call site by setting a relink-and-invoke method handle. The call site
+ * implementation is supposed to set this method handle as its target.
* @param relinkAndInvoke a relink-and-invoke method handle supplied by the {@link DynamicLinker}.
*/
public void initialize(MethodHandle relinkAndInvoke);
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/AbstractJavaLinker.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/AbstractJavaLinker.java Thu Oct 15 16:50:08 2015 -0700
@@ -111,8 +111,6 @@
/**
* A base class for both {@link StaticClassLinker} and {@link BeanLinker}. Deals with common aspects of property
* exposure and method calls for both static and instance facets of a class.
- *
- * @author Attila Szegedi
*/
abstract class AbstractJavaLinker implements GuardingDynamicLinker {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/AccessibleMembersLookup.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/AccessibleMembersLookup.java Thu Oct 15 16:50:08 2015 -0700
@@ -98,8 +98,6 @@
* public, or belongs to a restricted-access package. In that case, it is required to lookup a member in a publicly
* accessible superclass or implemented interface of the class, and use it instead of the member discovered on the
* class.
- *
- * @author Attila Szegedi
*/
class AccessibleMembersLookup {
private final Map<MethodSignature, Method> methods;
@@ -140,8 +138,6 @@
/**
* A helper class that represents a method signature - name and argument types.
- *
- * @author Attila Szegedi
*/
static final class MethodSignature {
private final String name;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ApplicableOverloadedMethods.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ApplicableOverloadedMethods.java Thu Oct 15 16:50:08 2015 -0700
@@ -90,8 +90,6 @@
/**
* Represents overloaded methods applicable to a specific call site signature.
- *
- * @author Attila Szegedi
*/
class ApplicableOverloadedMethods {
private final List<SingleDynamicMethod> methods;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/BeanLinker.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/BeanLinker.java Thu Oct 15 16:50:08 2015 -0700
@@ -102,8 +102,6 @@
/**
* A class that provides linking capabilities for a single POJO class. Normally not used directly, but managed by
* {@link BeansLinker}.
- *
- * @author Attila Szegedi
*/
class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicLinker {
BeanLinker(final Class<?> clazz) {
@@ -316,8 +314,6 @@
/**
* Contains methods to adapt an item getter/setter method handle to the requested type, optionally binding it to a
* fixed key first.
- * @author Attila Szegedi
- * @version $Id: $
*/
private static class Binder {
private final LinkerServices linkerServices;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/BeansLinker.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/BeansLinker.java Thu Oct 15 16:50:08 2015 -0700
@@ -125,8 +125,6 @@
* <p><strong>Variable argument invocation</strong> is handled for both methods and constructors.</p>
* <p>Currently, only public fields and methods are supported. Any Lookup objects passed in the
* {@link LinkRequest}s are ignored and {@link MethodHandles#publicLookup()} is used instead.</p>
- *
- * @author Attila Szegedi
*/
public class BeansLinker implements GuardingDynamicLinker {
private static final ClassValue<TypeBasedGuardingDynamicLinker> linkers = new ClassValue<TypeBasedGuardingDynamicLinker>() {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/CallerSensitiveDynamicMethod.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/CallerSensitiveDynamicMethod.java Thu Oct 15 16:50:08 2015 -0700
@@ -98,8 +98,6 @@
* caller sensitive, it doesn't cache a method handle but rather uses the passed lookup object in
* {@link #getTarget(java.lang.invoke.MethodHandles.Lookup)} to unreflect a method handle from the reflective member on
* every request.
- *
- * @author Attila Szegedi
*/
class CallerSensitiveDynamicMethod extends SingleDynamicMethod {
// Typed as "AccessibleObject" as it can be either a method or a constructor.
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ClassLinker.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ClassLinker.java Thu Oct 15 16:50:08 2015 -0700
@@ -93,7 +93,6 @@
* A linker for java.lang.Class objects. Provides a synthetic property "static" that allows access to static fields and
* methods on the class (respecting property getter/setter conventions). Note that Class objects are not recognized by
* the Dynalink as constructors for the instances of the class, {@link StaticClass} is used for this purpose.
- * @author Attila Szegedi
*/
class ClassLinker extends BeanLinker {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ClassString.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/ClassString.java Thu Oct 15 16:50:08 2015 -0700
@@ -92,8 +92,9 @@
import jdk.internal.dynalink.support.TypeUtilities;
/**
- *
- * @author Attila Szegedi
+ * Represents a sequence of {@link Class} objects, useful for representing method signatures. Provides value
+ * semantics for using them as map keys, as well as specificity calculations and applicability checks as per
+ * JLS.
*/
final class ClassString {
/**
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/DynamicMethod.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/DynamicMethod.java Thu Oct 15 16:50:08 2015 -0700
@@ -93,8 +93,6 @@
* overloaded methods will perform overload resolution (actually, it will perform partial overloaded resolution at link
* time, but if that fails to identify exactly one target method, it will generate a method handle that will perform the
* rest of the overload resolution at invocation time for actual argument types).
- *
- * @author Attila Szegedi
*/
abstract class DynamicMethod {
private final String name;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/FacetIntrospector.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/FacetIntrospector.java Thu Oct 15 16:50:08 2015 -0700
@@ -97,7 +97,6 @@
/**
* Base for classes that expose class field and method information to an {@link AbstractJavaLinker}. There are
* subclasses for instance (bean) and static facet of a class.
- * @author Attila Szegedi
*/
abstract class FacetIntrospector {
private final Class<?> clazz;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/GuardedInvocationComponent.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/GuardedInvocationComponent.java Thu Oct 15 16:50:08 2015 -0700
@@ -91,8 +91,6 @@
* {@link AbstractJavaLinker}. In addition to holding a guarded invocation, it holds semantic information about its
* guard. All guards produced in the AbstractJavaLinker are either "Class.isInstance()" or "getClass() == clazz"
* expressions. This allows choosing the most restrictive guard as the guard for the composition of two components.
- * @author Attila Szegedi
- * @version $Id: $
*/
class GuardedInvocationComponent {
enum ValidationType {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/MaximallySpecific.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/MaximallySpecific.java Thu Oct 15 16:50:08 2015 -0700
@@ -94,8 +94,6 @@
/**
* Utility class that encapsulates the algorithm for choosing the maximally specific methods.
- *
- * @author Attila Szegedi
*/
class MaximallySpecific {
/**
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/OverloadedDynamicMethod.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/OverloadedDynamicMethod.java Thu Oct 15 16:50:08 2015 -0700
@@ -101,8 +101,6 @@
* Represents a group of {@link SingleDynamicMethod} objects that represents all overloads of a particular name (or all
* constructors) for a particular class. Correctly handles overload resolution, variable arity methods, and caller
* sensitive methods within the overloads.
- *
- * @author Attila Szegedi
*/
class OverloadedDynamicMethod extends DynamicMethod {
/**
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/OverloadedMethod.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/OverloadedMethod.java Thu Oct 15 16:50:08 2015 -0700
@@ -100,8 +100,6 @@
* a vararg subset depending on the subclass. The method is for a fixed number of arguments though (as it is generated
* for a concrete call site). As such, all methods in the subset can be invoked with the specified number of arguments
* (exactly matching for fixargs, or having less than or equal fixed arguments, for varargs).
- *
- * @author Attila Szegedi
*/
class OverloadedMethod {
private final Map<ClassString, MethodHandle> argTypesToMethods = new ConcurrentHashMap<>();
@@ -122,7 +120,7 @@
fixArgMethods = new ArrayList<>(methodHandles.size());
varArgMethods = new ArrayList<>(methodHandles.size());
final int argNum = callSiteType.parameterCount();
- for(MethodHandle mh: methodHandles) {
+ for(final MethodHandle mh: methodHandles) {
if(mh.isVarargsCollector()) {
final MethodHandle asFixed = mh.asFixedArity();
if(argNum == asFixed.type().parameterCount()) {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/SimpleDynamicMethod.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/SimpleDynamicMethod.java Thu Oct 15 16:50:08 2015 -0700
@@ -93,8 +93,6 @@
* {@link #getTarget(Lookup)}. Can be used in general to represents dynamic methods bound to a single method handle,
* even if that handle is not mapped to a Java method, i.e. as a wrapper around field getters/setters, array element
* getters/setters, etc.
- *
- * @author Attila Szegedi
*/
class SimpleDynamicMethod extends SingleDynamicMethod {
private final MethodHandle target;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/SingleDynamicMethod.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/SingleDynamicMethod.java Thu Oct 15 16:50:08 2015 -0700
@@ -97,7 +97,6 @@
* Base class for dynamic methods that dispatch to a single target Java method or constructor. Handles adaptation of the
* target method to a call site type (including mapping variable arity methods to a call site signature with different
* arity).
- * @author Attila Szegedi
*/
abstract class SingleDynamicMethod extends DynamicMethod {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/StaticClassLinker.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/StaticClassLinker.java Thu Oct 15 16:50:08 2015 -0700
@@ -99,7 +99,6 @@
/**
* Provides a linker for the {@link StaticClass} objects.
- * @author Attila Szegedi
*/
class StaticClassLinker implements TypeBasedGuardingDynamicLinker {
private static final ClassValue<SingleClassStaticsLinker> linkers = new ClassValue<SingleClassStaticsLinker>() {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/ConversionComparator.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/ConversionComparator.java Thu Oct 15 16:50:08 2015 -0700
@@ -90,15 +90,17 @@
* of additional conversions. The static way of selecting the "most specific" method will fail more often, because there
* will be multiple maximally specific method with unrelated signatures. In these cases, language runtimes can be asked
* to resolve the ambiguity by expressing preferences for one conversion over the other.
- * @author Attila Szegedi
*/
public interface ConversionComparator {
/**
* Enumeration of possible outcomes of comparing one conversion to another.
*/
enum Comparison {
+ /** The conversions cannot be compared. **/
INDETERMINATE,
+ /** The first conversion is better than the second one. **/
TYPE_1_BETTER,
+ /** The second conversion is better than the first one. **/
TYPE_2_BETTER,
}
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/GuardedInvocation.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/GuardedInvocation.java Thu Oct 15 16:50:08 2015 -0700
@@ -101,8 +101,6 @@
* external invalidation of the invocation handle. The invocation handle is suitable for invocation if the guard
* handle returns true for its arguments, and as long as the switch point is not invalidated. Both the guard and the
* switch point are optional; neither, one, or both can be present.
- *
- * @author Attila Szegedi
*/
public class GuardedInvocation {
private final MethodHandle invocation;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/GuardingDynamicLinker.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/GuardingDynamicLinker.java Thu Oct 15 16:50:08 2015 -0700
@@ -89,8 +89,6 @@
* very least, it depends on the receiver belonging to the language runtime of the linker). Language runtime
* implementors will normally implement one for their own language, and declare it in the
* <tt>META-INF/services/jdk.internal.dynalink.linker.GuardingDynamicLinker</tt> file within their JAR file.
- *
- * @author Attila Szegedi
*/
public interface GuardingDynamicLinker {
/**
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/GuardingTypeConverterFactory.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/GuardingTypeConverterFactory.java Thu Oct 15 16:50:08 2015 -0700
@@ -91,8 +91,6 @@
* very likely want to implement {@link ConversionComparator} interface too, as your additional language-specific
* conversions, in absence of a strategy for prioritizing these conversions, will cause more ambiguity in selecting the
* correct overload when trying to link to an overloaded POJO method.
- *
- * @author Attila Szegedi
*/
public interface GuardingTypeConverterFactory {
/**
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/LinkRequest.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/LinkRequest.java Thu Oct 15 16:50:08 2015 -0700
@@ -89,8 +89,6 @@
/**
* Represents a request to link a particular invocation at a particular call site. Instances of these requests are being
* passed to {@link GuardingDynamicLinker}.
- *
- * @author Attila Szegedi
*/
public interface LinkRequest {
/**
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/LinkerServices.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/LinkerServices.java Thu Oct 15 16:50:08 2015 -0700
@@ -95,8 +95,6 @@
* Interface for services provided to {@link GuardingDynamicLinker} instances by the {@link DynamicLinker} that owns
* them. You can think of it as the interface of the {@link DynamicLinker} that faces the {@link GuardingDynamicLinker}
* s.
- *
- * @author Attila Szegedi
*/
public interface LinkerServices {
/**
@@ -130,7 +128,11 @@
* {@link MethodHandles#filterArguments(MethodHandle, int, MethodHandle...)} with
* {@link GuardingTypeConverterFactory}-produced type converters as filters.
*/
- public MethodHandle asTypeLosslessReturn(MethodHandle handle, MethodType fromType);
+ public default MethodHandle asTypeLosslessReturn(final MethodHandle handle, final MethodType fromType) {
+ final Class<?> handleReturnType = handle.type().returnType();
+ return asType(handle, TypeUtilities.isConvertibleWithoutLoss(handleReturnType, fromType.returnType()) ?
+ fromType : fromType.changeReturnType(handleReturnType));
+ }
/**
* Given a source and target type, returns a method handle that converts between them. Never returns null; in worst
@@ -188,23 +190,4 @@
* @return a method handle with parameters and/or return type potentially filtered for wrapping and unwrapping.
*/
public MethodHandle filterInternalObjects(final MethodHandle target);
-
- /**
- * If we could just use Java 8 constructs, then {@code asTypeSafeReturn} would be a method with default
- * implementation. Since we can't do that, we extract common default implementations into this static class.
- */
- public static class Implementation {
- /**
- * Default implementation for {@link LinkerServices#asTypeLosslessReturn(MethodHandle, MethodType)}.
- * @param linkerServices the linker services that delegates to this implementation
- * @param handle the passed handle
- * @param fromType the passed type
- * @return the converted method handle, as per the {@code asTypeSafeReturn} semantics.
- */
- public static MethodHandle asTypeLosslessReturn(final LinkerServices linkerServices, final MethodHandle handle, final MethodType fromType) {
- final Class<?> handleReturnType = handle.type().returnType();
- return linkerServices.asType(handle, TypeUtilities.isConvertibleWithoutLoss(handleReturnType, fromType.returnType()) ?
- fromType : fromType.changeReturnType(handleReturnType));
- }
- }
}
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/TypeBasedGuardingDynamicLinker.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/TypeBasedGuardingDynamicLinker.java Thu Oct 15 16:50:08 2015 -0700
@@ -88,8 +88,6 @@
* argument at linking invocation time. (The first argument is usually the receiver class). Most language-specific
* linkers will fall into this category, as they recognize their native objects as Java objects of classes implementing
* a specific language-native interface or superclass. The linker mechanism can optimize the dispatch for these linkers.
- *
- * @author Attila Szegedi
*/
public interface TypeBasedGuardingDynamicLinker extends GuardingDynamicLinker {
/**
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/AbstractCallSiteDescriptor.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/AbstractCallSiteDescriptor.java Thu Oct 15 16:50:08 2015 -0700
@@ -91,7 +91,6 @@
/**
* A base class for call site descriptor implementations. Provides reconstruction of the name from the tokens, as well
* as a generally useful {@code equals} and {@code hashCode} methods.
- * @author Attila Szegedi
*/
public abstract class AbstractCallSiteDescriptor implements CallSiteDescriptor {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/AbstractRelinkableCallSite.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/AbstractRelinkableCallSite.java Thu Oct 15 16:50:08 2015 -0700
@@ -90,8 +90,6 @@
/**
* A basic implementation of the {@link RelinkableCallSite} as a {@link MutableCallSite} subclass.
- *
- * @author Attila Szegedi
*/
public abstract class AbstractRelinkableCallSite extends MutableCallSite implements RelinkableCallSite {
private final CallSiteDescriptor descriptor;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/BottomGuardingDynamicLinker.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/BottomGuardingDynamicLinker.java Thu Oct 15 16:50:08 2015 -0700
@@ -91,8 +91,6 @@
/**
* A linker that can't link any call site. Only used internally by {@link CompositeTypeBasedGuardingDynamicLinker}. Can
* be used by other language runtimes if they need it though.
- *
- * @author Attila Szegedi
*/
public class BottomGuardingDynamicLinker implements TypeBasedGuardingDynamicLinker {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CallSiteDescriptorFactory.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CallSiteDescriptorFactory.java Thu Oct 15 16:50:08 2015 -0700
@@ -97,12 +97,12 @@
import jdk.internal.dynalink.CallSiteDescriptor;
/**
- * Usable as a default factory for call site descriptor implementations. It is weakly canonicalizing, meaning it will
- * return the same immutable call site descriptor for identical inputs, i.e. repeated requests for a descriptor
- * signifying public lookup for "dyn:getProp:color" of type "Object(Object)" will return the same object as long as
- * a previously created, at least softly reachable one exists. It also uses several different implementations of the
- * {@link CallSiteDescriptor} internally, and chooses the most space-efficient one based on the input.
- * @author Attila Szegedi
+ * Usable as a default factory for call site descriptor implementations. It is weakly canonicalizing, meaning
+ * it will return the same immutable call site descriptor for identical inputs, i.e. repeated requests for a
+ * descriptor signifying public lookup for {@code "dyn:getProp:color"} of type {@code Object(Object)} will
+ * return the same object as long as a previously created, at least softly reachable one exists. It also uses
+ * several different implementations of the {@link CallSiteDescriptor} internally, and chooses the most
+ * space-efficient one based on the input.
*/
public class CallSiteDescriptorFactory {
private static final WeakHashMap<CallSiteDescriptor, Reference<CallSiteDescriptor>> publicDescs =
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/ClassMap.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/ClassMap.java Thu Oct 15 16:50:08 2015 -0700
@@ -96,7 +96,6 @@
* A dual map that can either strongly or weakly reference a given class depending on whether the class is visible from
* a class loader or not.
*
- * @author Attila Szegedi
* @param <T> the type of the values in the map
*/
public abstract class ClassMap<T> {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CompositeGuardingDynamicLinker.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CompositeGuardingDynamicLinker.java Thu Oct 15 16:50:08 2015 -0700
@@ -95,8 +95,6 @@
* A {@link GuardingDynamicLinker} that delegates sequentially to a list of other guarding dynamic linkers. The first
* value returned from a component linker other than null is returned. If no component linker returns an invocation,
* null is returned.
- *
- * @author Attila Szegedi
*/
public class CompositeGuardingDynamicLinker implements GuardingDynamicLinker, Serializable {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CompositeTypeBasedGuardingDynamicLinker.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/CompositeTypeBasedGuardingDynamicLinker.java Thu Oct 15 16:50:08 2015 -0700
@@ -98,8 +98,6 @@
* 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.
- *
- * @author Attila Szegedi
*/
public class CompositeTypeBasedGuardingDynamicLinker implements TypeBasedGuardingDynamicLinker, Serializable {
private static final long serialVersionUID = 1L;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/DefaultCallSiteDescriptor.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/DefaultCallSiteDescriptor.java Thu Oct 15 16:50:08 2015 -0700
@@ -91,7 +91,6 @@
* A default, fairly light implementation of a call site descriptor used for describing non-standard operations. It does
* not store {@link Lookup} objects but always returns the public lookup from its {@link #getLookup()} method. If you
* need to support non-public lookup, you can use {@link LookupCallSiteDescriptor}.
- * @author Attila Szegedi
*/
class DefaultCallSiteDescriptor extends AbstractCallSiteDescriptor {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/Guards.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/Guards.java Thu Oct 15 16:50:08 2015 -0700
@@ -94,7 +94,6 @@
/**
* Utility methods for creating typical guards. TODO: introduce reasonable caching of created guards.
*
- * @author Attila Szegedi
*/
public class Guards {
private static final Logger LOG = Logger
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/LinkRequestImpl.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/LinkRequestImpl.java Thu Oct 15 16:50:08 2015 -0700
@@ -89,8 +89,6 @@
/**
* Default implementation of the {@link LinkRequest}, representing a link request to a call site that passes no language
* runtime specific native context arguments on the stack.
- *
- * @author Attila Szegedi
*/
public class LinkRequestImpl implements LinkRequest {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/LinkerServicesImpl.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/LinkerServicesImpl.java Thu Oct 15 16:50:08 2015 -0700
@@ -94,8 +94,6 @@
/**
* Default implementation of the {@link LinkerServices} interface.
- *
- * @author Attila Szegedi
*/
public class LinkerServicesImpl implements LinkerServices {
@@ -132,11 +130,6 @@
}
@Override
- public MethodHandle asTypeLosslessReturn(final MethodHandle handle, final MethodType fromType) {
- return Implementation.asTypeLosslessReturn(this, handle, fromType);
- }
-
- @Override
public MethodHandle getTypeConverter(final Class<?> sourceType, final Class<?> targetType) {
return typeConverterFactory.getTypeConverter(sourceType, targetType);
}
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/Lookup.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/Lookup.java Thu Oct 15 16:50:08 2015 -0700
@@ -93,8 +93,6 @@
/**
* A wrapper around MethodHandles.Lookup that masks checked exceptions in those cases when you're looking up methods
* within your own codebase (therefore it is an error if they are not present).
- *
- * @author Attila Szegedi
*/
public class Lookup {
private final MethodHandles.Lookup lookup;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/LookupCallSiteDescriptor.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/LookupCallSiteDescriptor.java Thu Oct 15 16:50:08 2015 -0700
@@ -89,7 +89,6 @@
/**
* A call site descriptor that stores a specific {@link Lookup}. It does not, however, store static bootstrap arguments.
- * @author Attila Szegedi
*/
class LookupCallSiteDescriptor extends DefaultCallSiteDescriptor {
private final Lookup lookup;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/NameCodec.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/NameCodec.java Thu Oct 15 16:50:08 2015 -0700
@@ -99,8 +99,6 @@
* have your own way of creating call site descriptors, but you still delegate to this method of the default factory
* (it is recommended that you do), then you have demangling handled for you already, and only need to ensure that you
* mangle the names when you're emitting them in the bytecode.
- *
- * @author Attila Szegedi
*/
public class NameCodec {
private static final char ESCAPE_CHAR = '\\';
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/RuntimeContextLinkRequestImpl.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/RuntimeContextLinkRequestImpl.java Thu Oct 15 16:50:08 2015 -0700
@@ -89,8 +89,6 @@
/**
* A link request implementation for call sites that pass language runtime specific context arguments on the stack. The
* context specific arguments should be the first "n" arguments.
- *
- * @author Attila Szegedi
*/
public class RuntimeContextLinkRequestImpl extends LinkRequestImpl {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/TypeConverterFactory.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/TypeConverterFactory.java Thu Oct 15 16:50:08 2015 -0700
@@ -103,8 +103,6 @@
* A factory for type converters. This class is the main implementation behind the
* {@link LinkerServices#asType(MethodHandle, MethodType)}. It manages the known {@link GuardingTypeConverterFactory}
* instances and creates appropriate converters for method handles.
- *
- * @author Attila Szegedi
*/
public class TypeConverterFactory {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/TypeUtilities.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/support/TypeUtilities.java Thu Oct 15 16:50:08 2015 -0700
@@ -96,8 +96,6 @@
/**
* Various static utility methods for testing type relationships.
- *
- * @author Attila Szegedi
*/
public class TypeUtilities {
static final Class<Object> OBJECT_CLASS = Object.class;
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornBeansLinker.java Wed Jul 05 20:54:03 2017 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornBeansLinker.java Thu Oct 15 16:50:08 2015 -0700
@@ -211,11 +211,6 @@
}
@Override
- public MethodHandle asTypeLosslessReturn(final MethodHandle handle, final MethodType fromType) {
- return Implementation.asTypeLosslessReturn(this, handle, fromType);
- }
-
- @Override
public MethodHandle getTypeConverter(final Class<?> sourceType, final Class<?> targetType) {
return linkerServices.getTypeConverter(sourceType, targetType);
}