aboutsummaryrefslogtreecommitdiff
path: root/src/jdk/nashorn/internal/lookup
diff options
context:
space:
mode:
authorattila <none@none>2014-08-20 10:26:01 +0200
committerattila <none@none>2014-08-20 10:26:01 +0200
commitf316c56df944b1f40c885d8b1df88e7deeab47f2 (patch)
tree6e361a5ea5259a0bc7eeea0bbe727e74187d418a /src/jdk/nashorn/internal/lookup
parent1e4829218e17571eeb9d45aa6e08aac68b7efffd (diff)
downloadjdk8u_nashorn-f316c56df944b1f40c885d8b1df88e7deeab47f2.tar.gz
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
8027958: NASHORN TEST: Create tests to test markdown javascript engine work with Nashorn 8028345: Remove nashorn repo "bin" scripts to avoid confusion with JDK bin launcher programs 8029090: Developers should be able to pass nashorn properties and enable/disable JFR from command line 8030169: Need regression test for bug JDK-8010731 8033105: Make sure Nashorn test harness can run zlib benchmark 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation. 8035820: Optimistic recompilation 8035836: Array performance improvements 8036127: Prototype filter needs to be applied to getter guard as well, not just getter 8036986: Test should check that correctly type is returned running with optimistic. If optimistic assumption was wrong we should get the right one. 8037086: Check that deoptimizing recompilations are correct 8037177: -Dnashorn.optimistic should be enabled by default, meaning that it has to be explicitly set to false to run with the jdk 8 style conservative types 8037534: Use scope types to determine optimistic types 8037572: Add more test cases to check static types 8037967: Broke the build, by commiting without saving the last review comment 8038223: Symbol trace debug output takes time 8038396: fix for the compiler expression evaluator to be more inquisitive about types 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework 8038406: Testability: as a first step of moving loggers away from the process global space, the Debug object now supports logging POJOs from log entries as an event queue, which can be introspected from test scripts. This is way better than screen scraping brittle and subject-to-change log output. 8038413: NPE in unboxInteger 8038416: Access to undefined scoped variables deoptimized too much 8038426: Move all loggers from process wide scope into Global scope 8038799: Guard and unbox boxed primitives types on setting them in Properties to avoid megamorphisism 8038945: Simplify strict undefined checks 8039044: Expand undefined intrinsics for all commutative combinators of scrict undefined checks 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects. 8040024: BranchOptimizer produces bad code for NaN FP comparison 8040089: Apply to call transform was incomplete. Now passes all tests and performance is back 8040093: Make sure that optimistic splitting works in optimistic types 8040102: Remove all references to Unsafe and definition of anonymous clases from the code 8040655: When processing a RewriteException debug object, the return value has already been reset to null. We need to catch this value before that. 8041434: Add synchronization to the common global constants structure 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies 8041905: Fix apply2call bug that prevented avatar.js unit tests from running correctly 8041995: Problems when loading tree expressions with several optimistic program points when optimistically initializing ObjectNodes 8042118: Separate types from symbols 8043002: Improve performance of Nashorn equality operators 8043003: Use strongly referenced generic invokers 8043004: Reduce variability at JavaAdapter call sites 8043132: Nashorn : all tests failed with java.security.AccessControlException 8043133: Fix corner cases of JDK-8041995 8043137: Collapse long sequences of NOP in Nashorn bytecode output 8043232: Index selection of overloaded java new constructors 8043235: Type-based optimizations interfere with continuation methods 8043431: Fix yet another corner case of JDK-8041995 8043504: Octane test harness was missing argument to print_always at one callsite, causing erroneous logging 8043605: Enable history for empty property maps 8043608: Make equality tests inline better 8043611: Move timing dependent benchmark for apply2call specialization to currently_failing. It is dependent that nothing takes machine time when doing the two runs, causing spurious assertions. Suggest running octane.raytrace manually instead to verify that this works, or incorporating it in the nightly test suite 8043632: Parallelize class installation and various script fixes. 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option. 8043956: Make code caching work with optimistic typing and lazy compilation 8044012: Integrate the latest best known performance flags int ant octane jobs, and make sure that it's easy to compare 'ant octane-nashorn' and 'ant octane-v8' at the push of a button. (or rather; the entry of a command line) 8044102: Ensure bechmark exclude list for Octane benchmarks is in only one place, project.properties, and fix benchmark harness 8044154: Nashorn : all tests failed with java.security.AccessControlException 8044171: Make optimistic exception handlers smaller 8044502: Get rid of global optimistic flag 8044518: Ensure exceptions related to optimistic recompilation are not serializable 8044533: Deoptimizing negation produces wrong result for zero 8044534: Constant folding for unary + should produce int for boolean literals 8044760: Avoid PropertyMap duplicate for global instances 8044786: Some tests fail with non-optimistic compilation 8044803: Unnecessary restOf check 8044816: On-demand compiled top-level program doesn't need :createProgramFunction 8044851: nashorn properties leak memory 8046013: TypeError: Cannot apply "with" to non script object 8046014: MultiGlobalCompiledScript should cache :createProgramFunction handle 8046025: AccessorProperty.getGetter is not threadsafe 8046026: CompiledFunction.relinkComposableInvoker assert is being hit 8046201: Avoid repeated flattening of nested ConsStrings 8046215: Running uncompilable scripts throws NullPointerException 8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager. 8046905: apply on apply is broken 8046921: Deoptimization type information peristence 8047035: (function() "hello")() crashes in Lexer with jdk9 8047057: Add a regression test for the passing test cases from JDK-8042304 8047067: all eval arguments need to be copied in Lower 8047078: Fuzzing bug discovered when ArrayLiteralNodes weren't immutable 8047166: 'do with({}) break ; while(0);' crashes in CodeGenerator 8047331: Assertion in CompiledFunction when running earley-boyer after Merge 8047357: More precise synthetic return + unreachable throw 8047359: large string size RangeError should be thrown rather than reporting negative length 8047369: Add regression tests for passing test cases of JDK-8024971 8047371: local variable declaration in TypeEvaluator should use ScriptObject.addOwnProperty instead of .set 8047728: (function(x){var o={x:0}; with(o){delete x} return o.x})() evaluates to 0 instead of undefined 8047959: bindings created for declarations in eval code are not mutable 8048009: Type info caching accidentally defeated 8048071: eval within 'with' statement does not use correct scope if with scope expression has a copy of eval 8048079: Persistent code store is broken after optimistic types merge 8048505: ScriptingFunctions.readFully couldn't handle file names represented as ConsStrings 8048586: String concatenation with optimistic types is slow 8048718: JSON.parse('{"0":0, "64":0}') throws ArrayindexOutOfBoundsException 8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes 8049086: Minor API convenience functions on "Java" object 8049222: JSType class exposes public mutable arrays 8049223: RewriteException class exposes public mutable arrays 8049242: Explicit constructor overload selection should work with StaticClass as well 8049318: Test hideLocationProperties.js fails on Window due to backslash in path 8049524: Global object initialization via javax.script API should be minimal 8050432: javax.script.filename variable should not be enumerable with nashorn engine's ENGINE_SCOPE bindings 8050964: OptimisticTypesPersistence.java should use java.util.Date instead of java.sql.Date 8051019: Separate src and test execution sandbox directories 8051346: Test262 tests for ECMAScript 5 now in branch "es5-tests" 8051439: Wrong type calculated for ADD operator with undefined operand 8051839: GuardedInvocation needs to clone an argument 8053908: jdeps is not PATH on Mac, results in ant clean test failure on Mac 8053910: ScriptObjectMirror causing havoc with Invocation interface 8053913: Auto format caused warning in CompositeTypeBasedGuardingDynamicLinker 8054223: Nashorn: AssertionError when use __DIR__ and ScriptEngine.eval() 8054411: Add nashorn.args.prepend system property 8054503: test/script/external/test262/test/suite/ch12/12.6/12.6.4/12.6.4-2.js fails with tip 8054651: Global.initConstructor and ScriptFunction.getPrototype(Object) can have stricter types 8054898: Avoid creation of empty type info files 8054993: type info cache may be disabled for test262 and tests explicitly changing that property should use @fork 8055034: jjs exits interactive mode if exception was thrown when trying to print value of last evaluated expression 8055042: Compile-time expression evaluator was missing variables 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally 8055139: test/script/trusted/JDK-8055107.js fails with access control exception 8055186: Backport Nashorn optimistic typing to 8u repository 8055529: Clean up the bin directory Reviewed-by: jlaskey, lagergren, sundar Contributed-by: marcus.largergren@oracle.com, hannes.wallnoefer@oracle.com, sundararajan.athijegannathan@oracle.com
Diffstat (limited to 'src/jdk/nashorn/internal/lookup')
-rw-r--r--src/jdk/nashorn/internal/lookup/Lookup.java56
-rw-r--r--src/jdk/nashorn/internal/lookup/MethodHandleFactory.java380
-rw-r--r--src/jdk/nashorn/internal/lookup/MethodHandleFunctionality.java25
3 files changed, 219 insertions, 242 deletions
diff --git a/src/jdk/nashorn/internal/lookup/Lookup.java b/src/jdk/nashorn/internal/lookup/Lookup.java
index 0dd2741e..57728509 100644
--- a/src/jdk/nashorn/internal/lookup/Lookup.java
+++ b/src/jdk/nashorn/internal/lookup/Lookup.java
@@ -68,6 +68,12 @@ public final class Lookup {
/** Method handle to the most generic of setters, the one that takes an Object */
public static final MethodType SET_OBJECT_TYPE = MH.type(void.class, Object.class, Object.class);
+ /** Method handle to the primitive getters, the one that returns an long/int/double */
+ public static final MethodType GET_PRIMITIVE_TYPE = MH.type(long.class, Object.class);
+
+ /** Method handle to the primitive getters, the one that returns an long/int/double */
+ public static final MethodType SET_PRIMITIVE_TYPE = MH.type(void.class, Object.class, long.class);
+
private Lookup() {
}
@@ -123,6 +129,53 @@ public final class Lookup {
}
/**
+ * This method filters primitive argument types using JavaScript semantics. For example,
+ * an (int) cast of a double in Java land is not the same thing as invoking toInt32 on it.
+ * If you are returning values to JavaScript that have to be of a specific type, this is
+ * the correct return value filter to use, as the explicitCastArguments just uses the
+ * Java boxing equivalents
+ *
+ * @param mh method handle for which to filter argument value
+ * @param n argument index
+ * @param from old argument type, the new one is given by the sent method handle
+ * @return method handle for appropriate argument type conversion
+ */
+ public static MethodHandle filterArgumentType(final MethodHandle mh, final int n, final Class<?> from) {
+ final Class<?> to = mh.type().parameterType(n);
+
+ if (from == int.class) {
+ //fallthru
+ } else if (from == long.class) {
+ if (to == int.class) {
+ return MH.filterArguments(mh, n, JSType.TO_INT32_L.methodHandle());
+ }
+ //fallthru
+ } else if (from == double.class) {
+ if (to == int.class) {
+ return MH.filterArguments(mh, n, JSType.TO_INT32_D.methodHandle());
+ } else if (to == long.class) {
+ return MH.filterArguments(mh, n, JSType.TO_UINT32_D.methodHandle());
+ }
+ //fallthru
+ } else if (!from.isPrimitive()) {
+ if (to == int.class) {
+ return MH.filterArguments(mh, n, JSType.TO_INT32.methodHandle());
+ } else if (to == long.class) {
+ return MH.filterArguments(mh, n, JSType.TO_UINT32.methodHandle());
+ } else if (to == double.class) {
+ return MH.filterArguments(mh, n, JSType.TO_NUMBER.methodHandle());
+ } else if (!to.isPrimitive()) {
+ return mh;
+ }
+
+ assert false : "unsupported Lookup.filterReturnType type " + from + " -> " + to;
+ }
+
+ //use a standard cast - we don't need to check JavaScript special cases
+ return MH.explicitCastArguments(mh, mh.type().changeParameterType(n, from));
+ }
+
+ /**
* This method filters primitive return types using JavaScript semantics. For example,
* an (int) cast of a double in Java land is not the same thing as invoking toInt32 on it.
* If you are returning values to JavaScript that have to be of a specific type, this is
@@ -139,6 +192,9 @@ public final class Lookup {
if (retType == int.class) {
//fallthru
} else if (retType == long.class) {
+ if (type == int.class) {
+ return MH.filterReturnValue(mh, JSType.TO_INT32_L.methodHandle());
+ }
//fallthru
} else if (retType == double.class) {
if (type == int.class) {
diff --git a/src/jdk/nashorn/internal/lookup/MethodHandleFactory.java b/src/jdk/nashorn/internal/lookup/MethodHandleFactory.java
index 34fe2eb6..8ef13d79 100644
--- a/src/jdk/nashorn/internal/lookup/MethodHandleFactory.java
+++ b/src/jdk/nashorn/internal/lookup/MethodHandleFactory.java
@@ -37,9 +37,12 @@ import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import jdk.nashorn.internal.runtime.ConsString;
+import jdk.nashorn.internal.runtime.Context;
import jdk.nashorn.internal.runtime.Debug;
-import jdk.nashorn.internal.runtime.DebugLogger;
import jdk.nashorn.internal.runtime.ScriptObject;
+import jdk.nashorn.internal.runtime.logging.DebugLogger;
+import jdk.nashorn.internal.runtime.logging.Loggable;
+import jdk.nashorn.internal.runtime.logging.Logger;
import jdk.nashorn.internal.runtime.options.Options;
/**
@@ -96,27 +99,9 @@ public final class MethodHandleFactory {
return obj.toString();
}
- private static final MethodHandleFunctionality STANDARD = new StandardMethodHandleFunctionality();
- private static final MethodHandleFunctionality FUNC;
-
- private static final String DEBUG_PROPERTY = "nashorn.methodhandles.debug";
- private static final DebugLogger LOG = new DebugLogger("methodhandles", DEBUG_PROPERTY);
-
- static {
- if (LOG.isEnabled() || Options.getBooleanProperty(DEBUG_PROPERTY)) {
- if (Options.getStringProperty(DEBUG_PROPERTY, "").equals("create")) {
- FUNC = new TraceCreateMethodHandleFunctionality();
- } else {
- FUNC = new TraceMethodHandleFunctionality();
- }
- } else {
- FUNC = STANDARD;
- }
- }
-
+ private static final MethodHandleFunctionality FUNC = new StandardMethodHandleFunctionality();
private static final boolean PRINT_STACKTRACE = Options.getBooleanProperty("nashorn.methodhandles.debug.stacktrace");
-
/**
* Return the method handle functionality used for all method handle operations
* @return a method handle functionality implementation
@@ -125,8 +110,11 @@ public final class MethodHandleFactory {
return FUNC;
}
- private static final MethodHandle TRACE = STANDARD.findStatic(LOOKUP, MethodHandleFactory.class, "traceArgs", MethodType.methodType(void.class, DebugLogger.class, String.class, int.class, Object[].class));
- private static final MethodHandle TRACE_RETURN = STANDARD.findStatic(LOOKUP, MethodHandleFactory.class, "traceReturn", MethodType.methodType(Object.class, DebugLogger.class, Object.class));
+ private static final MethodHandle TRACE = FUNC.findStatic(LOOKUP, MethodHandleFactory.class, "traceArgs", MethodType.methodType(void.class, DebugLogger.class, String.class, int.class, Object[].class));
+ private static final MethodHandle TRACE_RETURN = FUNC.findStatic(LOOKUP, MethodHandleFactory.class, "traceReturn", MethodType.methodType(Object.class, DebugLogger.class, Object.class));
+ private static final MethodHandle TRACE_RETURN_VOID = FUNC.findStatic(LOOKUP, MethodHandleFactory.class, "traceReturnVoid", MethodType.methodType(void.class, DebugLogger.class));
+
+ private static final String VOID_TAG = "[VOID]";
/**
* Tracer that is applied before a value is returned from the traced function. It will output the return
@@ -136,11 +124,20 @@ public final class MethodHandleFactory {
* @return return value unmodified
*/
static Object traceReturn(final DebugLogger logger, final Object value) {
- final String str = "\treturn: " + stripName(value) + " [type=" + (value == null ? "null" : stripName(value.getClass()) + ']');
- logger.log(TRACE_LEVEL, str);
+ if (logger.isEnabled()) {
+ final String str = " return" +
+ (VOID_TAG.equals(value) ?
+ ";" :
+ " " + stripName(value) + "; // [type=" + (value == null ? "null]" : stripName(value.getClass()) + ']'));
+ logger.log(TRACE_LEVEL, str);
+ }
return value;
}
+ static void traceReturnVoid(final DebugLogger logger) {
+ traceReturn(logger, VOID_TAG);
+ }
+
/**
* Tracer that is applied before a function is called, printing the arguments
*
@@ -203,7 +200,7 @@ public final class MethodHandleFactory {
if (arg instanceof ScriptObject) {
return arg.toString() +
- " (map=" + Debug.id((((ScriptObject)arg).getMap())) +
+ " (map=" + Debug.id(((ScriptObject)arg).getMap()) +
")";
}
@@ -214,29 +211,32 @@ public final class MethodHandleFactory {
* Add a debug printout to a method handle, tracing parameters and return values
*
* @param logger a specific logger to which to write the output
+ * @param level level over which to print
* @param mh method handle to trace
* @param tag start of trace message
* @return traced method handle
*/
- public static MethodHandle addDebugPrintout(final DebugLogger logger, final MethodHandle mh, final Object tag) {
- return addDebugPrintout(logger, mh, 0, true, tag);
+ public static MethodHandle addDebugPrintout(final DebugLogger logger, final Level level, final MethodHandle mh, final Object tag) {
+ return addDebugPrintout(logger, level, mh, 0, true, tag);
}
-
/**
* Add a debug printout to a method handle, tracing parameters and return values
*
* @param logger a specific logger to which to write the output
+ * @param level level over which to print
* @param mh method handle to trace
* @param paramStart first param to print/trace
* @param printReturnValue should we print/trace return value if available?
* @param tag start of trace message
* @return traced method handle
*/
- public static MethodHandle addDebugPrintout(final DebugLogger logger, final MethodHandle mh, final int paramStart, final boolean printReturnValue, final Object tag) {
+ public static MethodHandle addDebugPrintout(final DebugLogger logger, final Level level, final MethodHandle mh, final int paramStart, final boolean printReturnValue, final Object tag) {
final MethodType type = mh.type();
- if (logger != null && logger.levelAbove(TRACE_LEVEL)) {
+ //if there is no logger, or if it's set to log only coarser events
+ //than the trace level, skip and return
+ if (logger != null && logger.levelCoarserThan(level)) {
return mh;
}
@@ -253,191 +253,49 @@ public final class MethodHandleFactory {
asType(type.changeReturnType(void.class)));
final Class<?> retType = type.returnType();
- if (retType != void.class && printReturnValue) {
- final MethodHandle traceReturn = MethodHandles.insertArguments(TRACE_RETURN, 0, logger);
- trace = MethodHandles.filterReturnValue(trace,
- traceReturn.asType(
- traceReturn.type().changeParameterType(0, retType).changeReturnType(retType)));
+ if (printReturnValue) {
+ if (retType != void.class) {
+ final MethodHandle traceReturn = MethodHandles.insertArguments(TRACE_RETURN, 0, logger);
+ trace = MethodHandles.filterReturnValue(trace,
+ traceReturn.asType(
+ traceReturn.type().changeParameterType(0, retType).changeReturnType(retType)));
+ } else {
+ trace = MethodHandles.filterReturnValue(trace, MethodHandles.insertArguments(TRACE_RETURN_VOID, 0, logger));
+ }
}
return trace;
}
/**
- * The standard class that marshalls all method handle operations to the java.lang.invoke
+ * Class that marshalls all method handle operations to the java.lang.invoke
* package. This exists only so that it can be subclassed and method handles created from
* Nashorn made possible to instrument.
*
* All Nashorn classes should use the MethodHandleFactory for their method handle operations
*/
- private static class StandardMethodHandleFunctionality implements MethodHandleFunctionality {
-
- @Override
- public MethodHandle filterArguments(final MethodHandle target, final int pos, final MethodHandle... filters) {
- return MethodHandles.filterArguments(target, pos, filters);
- }
-
- @Override
- public MethodHandle filterReturnValue(final MethodHandle target, final MethodHandle filter) {
- return MethodHandles.filterReturnValue(target, filter);
- }
-
- @Override
- public MethodHandle guardWithTest(final MethodHandle test, final MethodHandle target, final MethodHandle fallback) {
- return MethodHandles.guardWithTest(test, target, fallback);
- }
-
- @Override
- public MethodHandle insertArguments(final MethodHandle target, final int pos, final Object... values) {
- return MethodHandles.insertArguments(target, pos, values);
- }
-
- @Override
- public MethodHandle dropArguments(final MethodHandle target, final int pos, final Class<?>... valueTypes) {
- return MethodHandles.dropArguments(target, pos, valueTypes);
- }
-
- @Override
- public MethodHandle dropArguments(final MethodHandle target, final int pos, final List<Class<?>> valueTypes) {
- return MethodHandles.dropArguments(target, pos, valueTypes);
- }
-
- @Override
- public MethodHandle asType(final MethodHandle handle, final MethodType type) {
- return handle.asType(type);
- }
-
- @Override
- public MethodHandle bindTo(final MethodHandle handle, final Object x) {
- return handle.bindTo(x);
- }
-
- @Override
- public MethodHandle foldArguments(final MethodHandle target, final MethodHandle combiner) {
- return MethodHandles.foldArguments(target, combiner);
- }
-
- @Override
- public MethodHandle explicitCastArguments(final MethodHandle target, final MethodType type) {
- return MethodHandles.explicitCastArguments(target, type);
- }
-
- @Override
- public MethodHandle arrayElementGetter(final Class<?> type) {
- return MethodHandles.arrayElementGetter(type);
- }
-
- @Override
- public MethodHandle arrayElementSetter(final Class<?> type) {
- return MethodHandles.arrayElementSetter(type);
- }
-
- @Override
- public MethodHandle throwException(final Class<?> returnType, final Class<? extends Throwable> exType) {
- return MethodHandles.throwException(returnType, exType);
- }
-
- @Override
- public MethodHandle constant(final Class<?> type, final Object value) {
- return MethodHandles.constant(type, value);
- }
-
- @Override
- public MethodHandle asCollector(final MethodHandle handle, final Class<?> arrayType, final int arrayLength) {
- return handle.asCollector(arrayType, arrayLength);
- }
+ @Logger(name="methodhandles")
+ private static class StandardMethodHandleFunctionality implements MethodHandleFunctionality, Loggable {
- @Override
- public MethodHandle asSpreader(final MethodHandle handle, final Class<?> arrayType, final int arrayLength) {
- return handle.asSpreader(arrayType, arrayLength);
- }
+ // for bootstrapping reasons, because a lot of static fields use MH for lookups, we
+ // need to set the logger when the Global object is finished. This means that we don't
+ // get instrumentation for public static final MethodHandle SOMETHING = MH... in the builtin
+ // classes, but that doesn't matter, because this is usually not where we want it
+ private DebugLogger log = DebugLogger.DISABLED_LOGGER;
- @Override
- public MethodHandle getter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {
- try {
- return explicitLookup.findGetter(clazz, name, type);
- } catch (final NoSuchFieldException | IllegalAccessException e) {
- throw new LookupException(e);
- }
+ public StandardMethodHandleFunctionality() {
}
@Override
- public MethodHandle staticGetter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {
- try {
- return explicitLookup.findStaticGetter(clazz, name, type);
- } catch (final NoSuchFieldException | IllegalAccessException e) {
- throw new LookupException(e);
- }
+ public DebugLogger initLogger(final Context context) {
+ return this.log = context.getLogger(this.getClass());
}
-
@Override
- public MethodHandle setter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {
- try {
- return explicitLookup.findSetter(clazz, name, type);
- } catch (final NoSuchFieldException | IllegalAccessException e) {
- throw new LookupException(e);
- }
+ public DebugLogger getLogger() {
+ return log;
}
- @Override
- public MethodHandle staticSetter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {
- try {
- return explicitLookup.findStaticSetter(clazz, name, type);
- } catch (final NoSuchFieldException | IllegalAccessException e) {
- throw new LookupException(e);
- }
- }
-
- @Override
- public MethodHandle find(final Method method) {
- try {
- return PUBLIC_LOOKUP.unreflect(method);
- } catch (final IllegalAccessException e) {
- throw new LookupException(e);
- }
- }
-
- @Override
- public MethodHandle findStatic(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type) {
- try {
- return explicitLookup.findStatic(clazz, name, type);
- } catch (final NoSuchMethodException | IllegalAccessException e) {
- throw new LookupException(e);
- }
- }
-
- @Override
- public MethodHandle findVirtual(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type) {
- try {
- return explicitLookup.findVirtual(clazz, name, type);
- } catch (final NoSuchMethodException | IllegalAccessException e) {
- throw new LookupException(e);
- }
- }
-
- @Override
- public SwitchPoint createSwitchPoint() {
- return new SwitchPoint();
- }
-
- @Override
- public MethodHandle guardWithTest(final SwitchPoint sp, final MethodHandle before, final MethodHandle after) {
- return sp.guardWithTest(before, after);
- }
-
- @Override
- public MethodType type(final Class<?> returnType, final Class<?>... paramTypes) {
- return MethodType.methodType(returnType, paramTypes);
- }
-
- }
-
- /**
- * Class used for instrumenting and debugging Nashorn generated method handles
- */
- private static class TraceMethodHandleFunctionality extends StandardMethodHandleFunctionality {
-
protected static String describe(final Object... data) {
final StringBuilder sb = new StringBuilder();
@@ -470,177 +328,215 @@ public final class MethodHandleFactory {
}
public MethodHandle debug(final MethodHandle master, final String str, final Object... args) {
- return addDebugPrintout(LOG, master, Integer.MAX_VALUE, false, str + ' ' + describe(args));
+ if (log.isEnabled()) {
+ if (PRINT_STACKTRACE) {
+ stacktrace(log);
+ }
+ return addDebugPrintout(log, Level.INFO, master, Integer.MAX_VALUE, false, str + ' ' + describe(args));
+ }
+ return master;
}
@Override
public MethodHandle filterArguments(final MethodHandle target, final int pos, final MethodHandle... filters) {
- final MethodHandle mh = super.filterArguments(target, pos, filters);
+ final MethodHandle mh = MethodHandles.filterArguments(target, pos, filters);
return debug(mh, "filterArguments", target, pos, filters);
}
@Override
public MethodHandle filterReturnValue(final MethodHandle target, final MethodHandle filter) {
- final MethodHandle mh = super.filterReturnValue(target, filter);
+ final MethodHandle mh = MethodHandles.filterReturnValue(target, filter);
return debug(mh, "filterReturnValue", target, filter);
}
@Override
public MethodHandle guardWithTest(final MethodHandle test, final MethodHandle target, final MethodHandle fallback) {
- final MethodHandle mh = super.guardWithTest(test, target, fallback);
+ final MethodHandle mh = MethodHandles.guardWithTest(test, target, fallback);
return debug(mh, "guardWithTest", test, target, fallback);
}
@Override
public MethodHandle insertArguments(final MethodHandle target, final int pos, final Object... values) {
- final MethodHandle mh = super.insertArguments(target, pos, values);
+ final MethodHandle mh = MethodHandles.insertArguments(target, pos, values);
return debug(mh, "insertArguments", target, pos, values);
}
@Override
public MethodHandle dropArguments(final MethodHandle target, final int pos, final Class<?>... values) {
- final MethodHandle mh = super.dropArguments(target, pos, values);
+ final MethodHandle mh = MethodHandles.dropArguments(target, pos, values);
return debug(mh, "dropArguments", target, pos, values);
}
@Override
public MethodHandle dropArguments(final MethodHandle target, final int pos, final List<Class<?>> values) {
- final MethodHandle mh = super.dropArguments(target, pos, values);
+ final MethodHandle mh = MethodHandles.dropArguments(target, pos, values);
return debug(mh, "dropArguments", target, pos, values);
}
@Override
public MethodHandle asType(final MethodHandle handle, final MethodType type) {
- final MethodHandle mh = super.asType(handle, type);
+ final MethodHandle mh = handle.asType(type);
return debug(mh, "asType", handle, type);
}
@Override
public MethodHandle bindTo(final MethodHandle handle, final Object x) {
- final MethodHandle mh = super.bindTo(handle, x);
+ final MethodHandle mh = handle.bindTo(x);
return debug(mh, "bindTo", handle, x);
}
@Override
public MethodHandle foldArguments(final MethodHandle target, final MethodHandle combiner) {
- final MethodHandle mh = super.foldArguments(target, combiner);
+ final MethodHandle mh = MethodHandles.foldArguments(target, combiner);
return debug(mh, "foldArguments", target, combiner);
}
@Override
public MethodHandle explicitCastArguments(final MethodHandle target, final MethodType type) {
- final MethodHandle mh = super.explicitCastArguments(target, type);
+ final MethodHandle mh = MethodHandles.explicitCastArguments(target, type);
return debug(mh, "explicitCastArguments", target, type);
}
@Override
public MethodHandle arrayElementGetter(final Class<?> type) {
- final MethodHandle mh = super.arrayElementGetter(type);
+ final MethodHandle mh = MethodHandles.arrayElementGetter(type);
return debug(mh, "arrayElementGetter", type);
}
@Override
public MethodHandle arrayElementSetter(final Class<?> type) {
- final MethodHandle mh = super.arrayElementSetter(type);
+ final MethodHandle mh = MethodHandles.arrayElementSetter(type);
return debug(mh, "arrayElementSetter", type);
}
@Override
public MethodHandle throwException(final Class<?> returnType, final Class<? extends Throwable> exType) {
- final MethodHandle mh = super.throwException(returnType, exType);
+ final MethodHandle mh = MethodHandles.throwException(returnType, exType);
return debug(mh, "throwException", returnType, exType);
}
@Override
+ public MethodHandle catchException(final MethodHandle target, final Class<? extends Throwable> exType, final MethodHandle handler) {
+ final MethodHandle mh = MethodHandles.catchException(target, exType, handler);
+ return debug(mh, "catchException", exType);
+ }
+
+ @Override
public MethodHandle constant(final Class<?> type, final Object value) {
- final MethodHandle mh = super.constant(type, value);
+ final MethodHandle mh = MethodHandles.constant(type, value);
return debug(mh, "constant", type, value);
}
@Override
public MethodHandle asCollector(final MethodHandle handle, final Class<?> arrayType, final int arrayLength) {
- final MethodHandle mh = super.asCollector(handle, arrayType, arrayLength);
+ final MethodHandle mh = handle.asCollector(arrayType, arrayLength);
return debug(mh, "asCollector", handle, arrayType, arrayLength);
}
@Override
public MethodHandle asSpreader(final MethodHandle handle, final Class<?> arrayType, final int arrayLength) {
- final MethodHandle mh = super.asSpreader(handle, arrayType, arrayLength);
+ final MethodHandle mh = handle.asSpreader(arrayType, arrayLength);
return debug(mh, "asSpreader", handle, arrayType, arrayLength);
}
@Override
public MethodHandle getter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {
- final MethodHandle mh = super.getter(explicitLookup, clazz, name, type);
- return debug(mh, "getter", explicitLookup, clazz, name, type);
+ try {
+ final MethodHandle mh = explicitLookup.findGetter(clazz, name, type);
+ return debug(mh, "getter", explicitLookup, clazz, name, type);
+ } catch (final NoSuchFieldException | IllegalAccessException e) {
+ throw new LookupException(e);
+ }
}
@Override
public MethodHandle staticGetter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {
- final MethodHandle mh = super.staticGetter(explicitLookup, clazz, name, type);
- return debug(mh, "static getter", explicitLookup, clazz, name, type);
+ try {
+ final MethodHandle mh = explicitLookup.findStaticGetter(clazz, name, type);
+ return debug(mh, "static getter", explicitLookup, clazz, name, type);
+ } catch (final NoSuchFieldException | IllegalAccessException e) {
+ throw new LookupException(e);
+ }
}
@Override
public MethodHandle setter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {
- final MethodHandle mh = super.setter(explicitLookup, clazz, name, type);
- return debug(mh, "setter", explicitLookup, clazz, name, type);
+ try {
+ final MethodHandle mh = explicitLookup.findSetter(clazz, name, type);
+ return debug(mh, "setter", explicitLookup, clazz, name, type);
+ } catch (final NoSuchFieldException | IllegalAccessException e) {
+ throw new LookupException(e);
+ }
}
@Override
public MethodHandle staticSetter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {
- final MethodHandle mh = super.staticSetter(explicitLookup, clazz, name, type);
- return debug(mh, "static setter", explicitLookup, clazz, name, type);
+ try {
+ final MethodHandle mh = explicitLookup.findStaticSetter(clazz, name, type);
+ return debug(mh, "static setter", explicitLookup, clazz, name, type);
+ } catch (final NoSuchFieldException | IllegalAccessException e) {
+ throw new LookupException(e);
+ }
}
@Override
public MethodHandle find(final Method method) {
- final MethodHandle mh = super.find(method);
- return debug(mh, "find", method);
+ try {
+ final MethodHandle mh = PUBLIC_LOOKUP.unreflect(method);
+ return debug(mh, "find", method);
+ } catch (final IllegalAccessException e) {
+ throw new LookupException(e);
+ }
}
@Override
public MethodHandle findStatic(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type) {
- final MethodHandle mh = super.findStatic(explicitLookup, clazz, name, type);
- return debug(mh, "findStatic", explicitLookup, clazz, name, type);
+ try {
+ final MethodHandle mh = explicitLookup.findStatic(clazz, name, type);
+ return debug(mh, "findStatic", explicitLookup, clazz, name, type);
+ } catch (final NoSuchMethodException | IllegalAccessException e) {
+ throw new LookupException(e);
+ }
+ }
+
+ @Override
+ public MethodHandle findSpecial(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type, final Class<?> thisClass) {
+ try {
+ final MethodHandle mh = explicitLookup.findSpecial(clazz, name, type, thisClass);
+ return debug(mh, "findSpecial", explicitLookup, clazz, name, type);
+ } catch (final NoSuchMethodException | IllegalAccessException e) {
+ throw new LookupException(e);
+ }
}
@Override
public MethodHandle findVirtual(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type) {
- final MethodHandle mh = super.findVirtual(explicitLookup, clazz, name, type);
- return debug(mh, "findVirtual", explicitLookup, clazz, name, type);
+ try {
+ final MethodHandle mh = explicitLookup.findVirtual(clazz, name, type);
+ return debug(mh, "findVirtual", explicitLookup, clazz, name, type);
+ } catch (final NoSuchMethodException | IllegalAccessException e) {
+ throw new LookupException(e);
+ }
}
@Override
public SwitchPoint createSwitchPoint() {
- final SwitchPoint sp = super.createSwitchPoint();
- LOG.log(TRACE_LEVEL, "createSwitchPoint ", sp);
+ final SwitchPoint sp = new SwitchPoint();
+ log.log(TRACE_LEVEL, "createSwitchPoint ", sp);
return sp;
}
@Override
public MethodHandle guardWithTest(final SwitchPoint sp, final MethodHandle before, final MethodHandle after) {
- final MethodHandle mh = super.guardWithTest(sp, before, after);
+ final MethodHandle mh = sp.guardWithTest(before, after);
return debug(mh, "guardWithTest", sp, before, after);
}
@Override
public MethodType type(final Class<?> returnType, final Class<?>... paramTypes) {
- final MethodType mt = super.type(returnType, paramTypes);
- LOG.log(TRACE_LEVEL, "methodType ", returnType, " ", Arrays.toString(paramTypes), " ", mt);
+ final MethodType mt = MethodType.methodType(returnType, paramTypes);
+ log.log(TRACE_LEVEL, "methodType ", returnType, " ", Arrays.toString(paramTypes), " ", mt);
return mt;
}
}
-
- /**
- * Class used for debugging Nashorn generated method handles
- */
- private static class TraceCreateMethodHandleFunctionality extends TraceMethodHandleFunctionality {
- @Override
- public MethodHandle debug(final MethodHandle master, final String str, final Object... args) {
- LOG.log(TRACE_LEVEL, str, " ", describe(args));
- stacktrace(LOG);
- return master;
- }
- }
}
diff --git a/src/jdk/nashorn/internal/lookup/MethodHandleFunctionality.java b/src/jdk/nashorn/internal/lookup/MethodHandleFunctionality.java
index c7dd83b2..756c0b7b 100644
--- a/src/jdk/nashorn/internal/lookup/MethodHandleFunctionality.java
+++ b/src/jdk/nashorn/internal/lookup/MethodHandleFunctionality.java
@@ -152,6 +152,17 @@ public interface MethodHandleFunctionality {
public MethodHandle throwException(Class<?> returnType, Class<? extends Throwable> exType);
/**
+ * Wrapper for {@link java.lang.invoke.MethodHandles#catchException(MethodHandle, Class, MethodHandle)}
+ *
+ * @param target target method
+ * @param exType exception type
+ * @param handler the method handle to call when exception is thrown
+ *
+ * @return exception thrower method handle
+ */
+ public MethodHandle catchException(final MethodHandle target, final Class<? extends Throwable> exType, final MethodHandle handler);
+
+ /**
* Wrapper for {@link java.lang.invoke.MethodHandles#constant(Class, Object)}
*
* @param type type of constant
@@ -286,6 +297,19 @@ public interface MethodHandleFunctionality {
public MethodHandle findVirtual(MethodHandles.Lookup explicitLookup, Class<?> clazz, String name, MethodType type);
/**
+ * Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#findSpecial(Class, String, MethodType, Class)}
+ *
+ * @param explicitLookup explicit lookup to be used
+ * @param clazz class to look in
+ * @param name name of method
+ * @param type method type
+ * @param thisClass thisClass
+ *
+ * @return method handle for virtual method
+ */
+ public MethodHandle findSpecial(MethodHandles.Lookup explicitLookup, Class<?> clazz, String name, MethodType type, final Class<?> thisClass);
+
+ /**
* Wrapper for SwitchPoint creation. Just like {@code new SwitchPoint()} but potentially
* tracked
*
@@ -313,5 +337,6 @@ public interface MethodHandleFunctionality {
* @return the method type
*/
public MethodType type(Class<?> returnType, Class<?>... paramTypes);
+
}