author | lagergren |
Thu, 20 Mar 2014 16:16:42 +0100 | |
changeset 24725 | 7bb1f687a852 |
parent 24719 | f726e9d67629 |
child 24729 | 2b13051f2122 |
permissions | -rw-r--r-- |
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
1 |
/* |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
4 |
* |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
10 |
* |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
15 |
* accompanied this code). |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
16 |
* |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
20 |
* |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
23 |
* questions. |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
24 |
*/ |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
25 |
package jdk.nashorn.internal.runtime; |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
26 |
|
24719 | 27 |
import static jdk.nashorn.internal.lookup.Lookup.MH; |
28 |
import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.INVALID_PROGRAM_POINT; |
|
29 |
import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.isValid; |
|
30 |
||
31 |
import java.lang.invoke.CallSite; |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
32 |
import java.lang.invoke.MethodHandle; |
24719 | 33 |
import java.lang.invoke.MethodHandles; |
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
34 |
import java.lang.invoke.MethodType; |
24719 | 35 |
import java.lang.invoke.MutableCallSite; |
36 |
import java.lang.invoke.SwitchPoint; |
|
37 |
import java.util.Map; |
|
38 |
import java.util.TreeMap; |
|
39 |
import jdk.internal.dynalink.support.CatchExceptionCombinator; |
|
40 |
import jdk.nashorn.internal.codegen.types.ArrayType; |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
41 |
import jdk.nashorn.internal.codegen.types.Type; |
24719 | 42 |
import jdk.nashorn.internal.ir.FunctionNode; |
43 |
import jdk.nashorn.internal.runtime.linker.Bootstrap; |
|
44 |
import jdk.nashorn.internal.runtime.options.Options; |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
45 |
|
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
46 |
/** |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
47 |
* An version of a JavaScript function, native or JavaScript. |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
48 |
* Supports lazily generating a constructor version of the invocation. |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
49 |
*/ |
24719 | 50 |
final class CompiledFunction { |
51 |
private static final boolean USE_FAST_REWRITE = Options.getBooleanProperty("nashorn.fastrewrite"); |
|
52 |
static { |
|
53 |
if(USE_FAST_REWRITE && CompiledFunction.class.getClassLoader() != null) { |
|
54 |
throw new AssertionError("-Dnashorn.fastrewrite can only be used with Nashorn in boot class path! (Try -Xbootclasspath/p:dist/nashorn.jar )"); |
|
55 |
} |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
56 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
57 |
|
24719 | 58 |
private static final MethodHandle NEWFILTER = findOwnMH("newFilter", Object.class, Object.class, Object.class); |
59 |
private static final MethodHandle RELINK_COMPOSABLE_INVOKER = findOwnMH("relinkComposableInvoker", void.class, CallSite.class, CompiledFunction.class, boolean.class); |
|
60 |
private static final MethodHandle HANDLE_REWRITE_EXCEPTION = findOwnMH("handleRewriteException", MethodHandle.class, CompiledFunction.class, OptimismInfo.class, RewriteException.class); |
|
61 |
private static final MethodHandle RESTOF_INVOKER = MethodHandles.exactInvoker(MethodType.methodType(Object.class, RewriteException.class)); |
|
62 |
||
63 |
private static final DebugLogger LOG = new DebugLogger("recompile", "nashorn.codegen.debug"); |
|
64 |
||
65 |
/** |
|
66 |
* The method type may be more specific than the invoker, if. e.g. |
|
67 |
* the invoker is guarded, and a guard with a generic object only |
|
68 |
* fallback, while the target is more specific, we still need the |
|
69 |
* more specific type for sorting |
|
70 |
*/ |
|
71 |
private MethodHandle invoker; |
|
72 |
private MethodHandle constructor; |
|
73 |
private OptimismInfo optimismInfo; |
|
74 |
||
75 |
CompiledFunction(final MethodHandle invoker) { |
|
76 |
this.invoker = invoker; |
|
77 |
} |
|
78 |
||
79 |
static CompiledFunction createBuiltInConstructor(final MethodHandle invoker) { |
|
80 |
return new CompiledFunction(MH.insertArguments(invoker, 0, false), |
|
81 |
createConstructorFromInvoker(MH.insertArguments(invoker, 0, true))); |
|
82 |
} |
|
83 |
||
84 |
CompiledFunction(final MethodHandle invoker, final MethodHandle constructor) { |
|
85 |
this(invoker); |
|
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17518
diff
changeset
|
86 |
this.constructor = constructor; |
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
87 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
88 |
|
24719 | 89 |
CompiledFunction(final MethodHandle invoker, final RecompilableScriptFunctionData functionData, final boolean isOptimistic) { |
90 |
this(invoker); |
|
91 |
if(isOptimistic) { |
|
92 |
optimismInfo = new OptimismInfo(functionData); |
|
93 |
} else { |
|
94 |
optimismInfo = null; |
|
95 |
} |
|
96 |
} |
|
97 |
||
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
98 |
@Override |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
99 |
public String toString() { |
24719 | 100 |
return "<callSiteType=" + invoker.type() + " invoker=" + invoker + " ctor=" + constructor + " weight=" + weight() + ">"; |
101 |
} |
|
102 |
||
103 |
boolean needsCallee() { |
|
104 |
return ScriptFunctionData.needsCallee(invoker); |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
105 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
106 |
|
24719 | 107 |
/** |
108 |
* Returns an invoker method handle for this function. Note that the handle is safely composable in |
|
109 |
* the sense that you can compose it with other handles using any combinators even if you can't affect call site |
|
110 |
* invalidation. If this compiled function is non-optimistic, then it returns the same value as |
|
111 |
* {@link #getInvoker()}. However, if the function is optimistic, then this handle will incur an overhead as it will |
|
112 |
* add an intermediate internal call site that can relink itself when the function needs to regenerate its code to |
|
113 |
* always point at the latest generated code version. |
|
114 |
* @return a guaranteed composable invoker method handle for this function. |
|
115 |
*/ |
|
116 |
MethodHandle createComposableInvoker() { |
|
117 |
return createComposableInvoker(false); |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
118 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
119 |
|
24719 | 120 |
/** |
121 |
* Returns an invoker method handle for this function when invoked as a constructor. Note that the handle should be |
|
122 |
* considered non-composable in the sense that you can only compose it with other handles using any combinators if |
|
123 |
* you can ensure that the composition is guarded by {@link #getOptimisticAssumptionsSwitchPoint()} if it's |
|
124 |
* non-null, and that you can relink the call site it is set into as a target if the switch point is invalidated. In |
|
125 |
* all other cases, use {@link #createComposableConstructor()}. |
|
126 |
* @return a direct constructor method handle for this function. |
|
127 |
*/ |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
128 |
MethodHandle getConstructor() { |
24719 | 129 |
if(constructor == null) { |
130 |
constructor = createConstructorFromInvoker(createInvokerForPessimisticCaller()); |
|
131 |
} |
|
132 |
||
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
133 |
return constructor; |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
134 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
135 |
|
24719 | 136 |
/** |
137 |
* Creates a version of the invoker intended for a pessimistic caller (return type is Object, no caller optimistic |
|
138 |
* program point available). |
|
139 |
* @return a version of the invoker intended for a pessimistic caller. |
|
140 |
*/ |
|
141 |
private MethodHandle createInvokerForPessimisticCaller() { |
|
142 |
return createInvoker(Object.class, INVALID_PROGRAM_POINT); |
|
143 |
} |
|
144 |
||
145 |
/** |
|
146 |
* Compose a constructor from an invoker. |
|
147 |
* |
|
148 |
* @param invoker invoker |
|
149 |
* @param needsCallee do we need to pass a callee |
|
150 |
* |
|
151 |
* @return the composed constructor |
|
152 |
*/ |
|
153 |
private static MethodHandle createConstructorFromInvoker(final MethodHandle invoker) { |
|
154 |
final boolean needsCallee = ScriptFunctionData.needsCallee(invoker); |
|
155 |
// If it was (callee, this, args...), permute it to (this, callee, args...). We're doing this because having |
|
156 |
// "this" in the first argument position is what allows the elegant folded composition of |
|
157 |
// (newFilter x constructor x allocator) further down below in the code. Also, ensure the composite constructor |
|
158 |
// always returns Object. |
|
159 |
final MethodHandle swapped = needsCallee ? swapCalleeAndThis(invoker) : invoker; |
|
160 |
||
161 |
final MethodHandle returnsObject = MH.asType(swapped, swapped.type().changeReturnType(Object.class)); |
|
162 |
||
163 |
final MethodType ctorType = returnsObject.type(); |
|
164 |
||
165 |
// Construct a dropping type list for NEWFILTER, but don't include constructor "this" into it, so it's actually |
|
166 |
// captured as "allocation" parameter of NEWFILTER after we fold the constructor into it. |
|
167 |
// (this, [callee, ]args...) => ([callee, ]args...) |
|
168 |
final Class<?>[] ctorArgs = ctorType.dropParameterTypes(0, 1).parameterArray(); |
|
169 |
||
170 |
// Fold constructor into newFilter that replaces the return value from the constructor with the originally |
|
171 |
// allocated value when the originally allocated value is a JS primitive (String, Boolean, Number). |
|
172 |
// (result, this, [callee, ]args...) x (this, [callee, ]args...) => (this, [callee, ]args...) |
|
173 |
final MethodHandle filtered = MH.foldArguments(MH.dropArguments(NEWFILTER, 2, ctorArgs), returnsObject); |
|
174 |
||
175 |
// allocate() takes a ScriptFunction and returns a newly allocated ScriptObject... |
|
176 |
if (needsCallee) { |
|
177 |
// ...we either fold it into the previous composition, if we need both the ScriptFunction callee object and |
|
178 |
// the newly allocated object in the arguments, so (this, callee, args...) x (callee) => (callee, args...), |
|
179 |
// or... |
|
180 |
return MH.foldArguments(filtered, ScriptFunction.ALLOCATE); |
|
181 |
} |
|
182 |
||
183 |
// ...replace the ScriptFunction argument with the newly allocated object, if it doesn't need the callee |
|
184 |
// (this, args...) filter (callee) => (callee, args...) |
|
185 |
return MH.filterArguments(filtered, 0, ScriptFunction.ALLOCATE); |
|
186 |
} |
|
187 |
||
188 |
/** |
|
189 |
* Permutes the parameters in the method handle from {@code (callee, this, ...)} to {@code (this, callee, ...)}. |
|
190 |
* Used when creating a constructor handle. |
|
191 |
* @param mh a method handle with order of arguments {@code (callee, this, ...)} |
|
192 |
* @return a method handle with order of arguments {@code (this, callee, ...)} |
|
193 |
*/ |
|
194 |
private static MethodHandle swapCalleeAndThis(final MethodHandle mh) { |
|
195 |
final MethodType type = mh.type(); |
|
196 |
assert type.parameterType(0) == ScriptFunction.class : type; |
|
197 |
assert type.parameterType(1) == Object.class : type; |
|
198 |
final MethodType newType = type.changeParameterType(0, Object.class).changeParameterType(1, ScriptFunction.class); |
|
199 |
final int[] reorder = new int[type.parameterCount()]; |
|
200 |
reorder[0] = 1; |
|
201 |
assert reorder[1] == 0; |
|
202 |
for (int i = 2; i < reorder.length; ++i) { |
|
203 |
reorder[i] = i; |
|
204 |
} |
|
205 |
return MethodHandles.permuteArguments(mh, newType, reorder); |
|
206 |
} |
|
207 |
||
208 |
/** |
|
209 |
* Returns an invoker method handle for this function when invoked as a constructor. Note that the handle is safely |
|
210 |
* composable in the sense that you can compose it with other handles using any combinators even if you can't affect |
|
211 |
* call site invalidation. If this compiled function is non-optimistic, then it returns the same value as |
|
212 |
* {@link #getConstructor()}. However, if the function is optimistic, then this handle will incur an overhead as it |
|
213 |
* will add an intermediate internal call site that can relink itself when the function needs to regenerate its code |
|
214 |
* to always point at the latest generated code version. |
|
215 |
* @return a guaranteed composable constructor method handle for this function. |
|
216 |
*/ |
|
217 |
MethodHandle createComposableConstructor() { |
|
218 |
return createComposableInvoker(true); |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
219 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
220 |
|
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
221 |
boolean hasConstructor() { |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
222 |
return constructor != null; |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
223 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
224 |
|
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
225 |
MethodType type() { |
24719 | 226 |
return invoker.type(); |
20570
b1c8d1e8013a
8025965: Specialized functions with same weight replace each other in TreeSet
hannesw
parents:
17756
diff
changeset
|
227 |
} |
b1c8d1e8013a
8025965: Specialized functions with same weight replace each other in TreeSet
hannesw
parents:
17756
diff
changeset
|
228 |
|
24719 | 229 |
int weight() { |
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
230 |
return weight(type()); |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
231 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
232 |
|
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
233 |
private static int weight(final MethodType type) { |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
234 |
if (isVarArgsType(type)) { |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
235 |
return Integer.MAX_VALUE; //if there is a varargs it should be the heavist and last fallback |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
236 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
237 |
|
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
238 |
int weight = Type.typeFor(type.returnType()).getWeight(); |
24719 | 239 |
for (int i = 0 ; i < type.parameterCount() ; i++) { |
240 |
final Class<?> paramType = type.parameterType(i); |
|
17518
2225a4f929c0
8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents:
16523
diff
changeset
|
241 |
final int pweight = Type.typeFor(paramType).getWeight() * 2; //params are more important than call types as return values are always specialized |
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
242 |
weight += pweight; |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
243 |
} |
24719 | 244 |
|
245 |
weight += type.parameterCount(); //more params outweigh few parameters |
|
246 |
||
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
247 |
return weight; |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
248 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
249 |
|
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
250 |
private static boolean isVarArgsType(final MethodType type) { |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
251 |
assert type.parameterCount() >= 1 : type; |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
252 |
return type.parameterType(type.parameterCount() - 1) == Object[].class; |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
253 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
254 |
|
24719 | 255 |
static boolean moreGenericThan(final MethodType mt0, final MethodType mt1) { |
256 |
return weight(mt0) > weight(mt1); |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
257 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
258 |
|
24719 | 259 |
boolean betterThanFinal(final CompiledFunction other, final MethodType callSiteMethodType) { |
260 |
// Prefer anything over nothing, as we can't compile new versions. |
|
261 |
if (other == null) { |
|
262 |
return true; |
|
263 |
} |
|
264 |
return betterThanFinal(type(), other.type(), callSiteMethodType); |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
265 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
266 |
|
24725
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24719
diff
changeset
|
267 |
static boolean betterThanFinal(final MethodType thisMethodType, final MethodType otherMethodType, final MethodType callSiteMethodType) { |
24719 | 268 |
final int thisParamCount = getParamCount(thisMethodType); |
269 |
final int otherParamCount = getParamCount(otherMethodType); |
|
270 |
final int callSiteRawParamCount = getParamCount(callSiteMethodType); |
|
271 |
final boolean csVarArg = callSiteRawParamCount == Integer.MAX_VALUE; |
|
272 |
// Subtract 1 for callee for non-vararg call sites |
|
273 |
final int callSiteParamCount = csVarArg ? callSiteRawParamCount : callSiteRawParamCount - 1; |
|
274 |
||
275 |
// Prefer the function that discards less parameters |
|
276 |
final int thisDiscardsParams = Math.max(callSiteParamCount - thisParamCount, 0); |
|
277 |
final int otherDiscardsParams = Math.max(callSiteParamCount - otherParamCount, 0); |
|
278 |
if(thisDiscardsParams < otherDiscardsParams) { |
|
279 |
return true; |
|
280 |
} |
|
281 |
if(thisDiscardsParams > otherDiscardsParams) { |
|
282 |
return false; |
|
283 |
} |
|
284 |
||
285 |
final boolean thisVarArg = thisParamCount == Integer.MAX_VALUE; |
|
286 |
final boolean otherVarArg = otherParamCount == Integer.MAX_VALUE; |
|
287 |
if(!(thisVarArg && otherVarArg && csVarArg)) { |
|
288 |
// At least one of them isn't vararg |
|
289 |
final Type[] thisType = toTypeWithoutCallee(thisMethodType, 0); // Never has callee |
|
290 |
final Type[] otherType = toTypeWithoutCallee(otherMethodType, 0); // Never has callee |
|
291 |
final Type[] callSiteType = toTypeWithoutCallee(callSiteMethodType, 1); // Always has callee |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
292 |
|
24719 | 293 |
int narrowWeightDelta = 0; |
294 |
int widenWeightDelta = 0; |
|
295 |
final int minParamsCount = Math.min(Math.min(thisParamCount, otherParamCount), callSiteParamCount); |
|
296 |
for(int i = 0; i < minParamsCount; ++i) { |
|
297 |
final int callSiteParamWeight = getParamType(i, callSiteType, csVarArg).getWeight(); |
|
298 |
// Delta is negative for narrowing, positive for widening |
|
299 |
final int thisParamWeightDelta = getParamType(i, thisType, thisVarArg).getWeight() - callSiteParamWeight; |
|
300 |
final int otherParamWeightDelta = getParamType(i, otherType, otherVarArg).getWeight() - callSiteParamWeight; |
|
301 |
// Only count absolute values of narrowings |
|
302 |
narrowWeightDelta += Math.max(-thisParamWeightDelta, 0) - Math.max(-otherParamWeightDelta, 0); |
|
303 |
// Only count absolute values of widenings |
|
304 |
widenWeightDelta += Math.max(thisParamWeightDelta, 0) - Math.max(otherParamWeightDelta, 0); |
|
305 |
} |
|
306 |
||
307 |
// If both functions accept more arguments than what is passed at the call site, account for ability |
|
308 |
// to receive Undefined un-narrowed in the remaining arguments. |
|
309 |
if(!thisVarArg) { |
|
310 |
for(int i = callSiteParamCount; i < thisParamCount; ++i) { |
|
311 |
narrowWeightDelta += Math.max(Type.OBJECT.getWeight() - thisType[i].getWeight(), 0); |
|
312 |
} |
|
313 |
} |
|
314 |
if(!otherVarArg) { |
|
315 |
for(int i = callSiteParamCount; i < otherParamCount; ++i) { |
|
316 |
narrowWeightDelta -= Math.max(Type.OBJECT.getWeight() - otherType[i].getWeight(), 0); |
|
317 |
} |
|
318 |
} |
|
319 |
||
320 |
// Prefer function that narrows less |
|
321 |
if(narrowWeightDelta < 0) { |
|
322 |
return true; |
|
323 |
} |
|
324 |
if(narrowWeightDelta > 0) { |
|
325 |
return false; |
|
326 |
} |
|
327 |
||
328 |
// Prefer function that widens less |
|
329 |
if(widenWeightDelta < 0) { |
|
330 |
return true; |
|
331 |
} |
|
332 |
if(widenWeightDelta > 0) { |
|
333 |
return false; |
|
334 |
} |
|
335 |
} |
|
336 |
||
337 |
// Prefer the function that exactly matches the arity of the call site. |
|
338 |
if(thisParamCount == callSiteParamCount && otherParamCount != callSiteParamCount) { |
|
339 |
return true; |
|
340 |
} |
|
341 |
if(thisParamCount != callSiteParamCount && otherParamCount == callSiteParamCount) { |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
342 |
return false; |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
343 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
344 |
|
24719 | 345 |
// Otherwise, neither function matches arity exactly. We also know that at this point, they both can receive |
346 |
// more arguments than call site, otherwise we would've already chosen the one that discards less parameters. |
|
347 |
// Note that variable arity methods are preferred, as they actually match the call site arity better, since they |
|
348 |
// really have arbitrary arity. |
|
349 |
if(thisVarArg) { |
|
350 |
if(!otherVarArg) { |
|
351 |
return true; // |
|
352 |
} |
|
353 |
} else if(otherVarArg) { |
|
354 |
return false; |
|
355 |
} |
|
356 |
||
357 |
// Neither is variable arity; chose the one that has less extra parameters. |
|
358 |
final int fnParamDelta = thisParamCount - otherParamCount; |
|
359 |
if(fnParamDelta < 0) { |
|
360 |
return true; |
|
361 |
} |
|
362 |
if(fnParamDelta > 0) { |
|
363 |
return false; |
|
364 |
} |
|
365 |
||
366 |
final int callSiteRetWeight = Type.typeFor(callSiteMethodType.returnType()).getWeight(); |
|
367 |
// Delta is negative for narrower return type, positive for wider return type |
|
368 |
final int thisRetWeightDelta = Type.typeFor(thisMethodType.returnType()).getWeight() - callSiteRetWeight; |
|
369 |
final int otherRetWeightDelta = Type.typeFor(otherMethodType.returnType()).getWeight() - callSiteRetWeight; |
|
370 |
||
371 |
// Prefer function that returns a less wide return type |
|
372 |
final int widenRetDelta = Math.max(thisRetWeightDelta, 0) - Math.max(otherRetWeightDelta, 0); |
|
373 |
if(widenRetDelta < 0) { |
|
374 |
return true; |
|
375 |
} |
|
376 |
if(widenRetDelta > 0) { |
|
377 |
return false; |
|
378 |
} |
|
379 |
||
380 |
// Prefer function that returns a less narrow return type |
|
381 |
final int narrowRetDelta = Math.max(-thisRetWeightDelta, 0) - Math.max(-otherRetWeightDelta, 0); |
|
382 |
if(narrowRetDelta < 0) { |
|
383 |
return true; |
|
384 |
} |
|
385 |
if(narrowRetDelta > 0) { |
|
386 |
return false; |
|
387 |
} |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
388 |
|
24719 | 389 |
throw new AssertionError(thisMethodType + " identically applicable to " + otherMethodType + " for " + callSiteMethodType); // Signatures are identical |
390 |
} |
|
391 |
||
24725
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24719
diff
changeset
|
392 |
private static Type[] toTypeWithoutCallee(final MethodType type, final int thisIndex) { |
24719 | 393 |
final int paramCount = type.parameterCount(); |
394 |
final Type[] t = new Type[paramCount - thisIndex]; |
|
395 |
for(int i = thisIndex; i < paramCount; ++i) { |
|
396 |
t[i - thisIndex] = Type.typeFor(type.parameterType(i)); |
|
397 |
} |
|
398 |
return t; |
|
399 |
} |
|
400 |
||
24725
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24719
diff
changeset
|
401 |
private static Type getParamType(final int i, final Type[] paramTypes, final boolean isVarArg) { |
24719 | 402 |
final int fixParamCount = paramTypes.length - (isVarArg ? 1 : 0); |
403 |
if(i < fixParamCount) { |
|
404 |
return paramTypes[i]; |
|
405 |
} |
|
406 |
assert isVarArg; |
|
407 |
return ((ArrayType)(paramTypes[paramTypes.length - 1])).getElementType(); |
|
408 |
} |
|
409 |
||
410 |
boolean matchesCallSite(final MethodType callSiteType) { |
|
411 |
if(!ScriptEnvironment.globalOptimistic()) { |
|
412 |
// Without optimistic recompilation, always choose the first eagerly compiled version. |
|
413 |
return true; |
|
414 |
} |
|
415 |
||
416 |
final MethodType type = type(); |
|
417 |
final int fnParamCount = getParamCount(type); |
|
418 |
final boolean isVarArg = fnParamCount == Integer.MAX_VALUE; |
|
419 |
if(isVarArg) { |
|
420 |
return true; |
|
421 |
} |
|
422 |
||
423 |
final int csParamCount = getParamCount(callSiteType); |
|
424 |
final boolean csIsVarArg = csParamCount == Integer.MAX_VALUE; |
|
425 |
final int thisThisIndex = needsCallee() ? 1 : 0; // Index of "this" parameter in this function's type |
|
426 |
||
24725
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24719
diff
changeset
|
427 |
final int fnParamCountNoCallee = fnParamCount - thisThisIndex; |
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24719
diff
changeset
|
428 |
final int minParams = Math.min(csParamCount - 1, fnParamCountNoCallee); // callSiteType always has callee, so subtract 1 |
24719 | 429 |
// We must match all incoming parameters, except "this". Starting from 1 to skip "this". |
430 |
for(int i = 1; i < minParams; ++i) { |
|
431 |
final Type fnType = Type.typeFor(type.parameterType(i + thisThisIndex)); |
|
432 |
final Type csType = csIsVarArg ? Type.OBJECT : Type.typeFor(callSiteType.parameterType(i + 1)); |
|
433 |
if(!fnType.isEquivalentTo(csType)) { |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
434 |
return false; |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
435 |
} |
24719 | 436 |
} |
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
437 |
|
24719 | 438 |
// Must match any undefined parameters to Object type. |
439 |
for(int i = minParams; i < fnParamCountNoCallee; ++i) { |
|
440 |
if(!Type.typeFor(type.parameterType(i + thisThisIndex)).isEquivalentTo(Type.OBJECT)) { |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
441 |
return false; |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
442 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
443 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
444 |
|
24719 | 445 |
return true; |
446 |
} |
|
447 |
||
448 |
private static int getParamCount(final MethodType type) { |
|
449 |
final int paramCount = type.parameterCount(); |
|
450 |
return type.parameterType(paramCount - 1).isArray() ? Integer.MAX_VALUE : paramCount; |
|
451 |
} |
|
452 |
||
453 |
/** |
|
454 |
* Returns the switch point embodying the optimistic assumptions in this compiled function. It should be used to |
|
455 |
* guard any linking to the function's invoker or constructor. |
|
456 |
* @return the switch point embodying the optimistic assumptions in this compiled function. Null is returned if the |
|
457 |
* function has no optimistic assumptions. |
|
458 |
*/ |
|
459 |
SwitchPoint getOptimisticAssumptionsSwitchPoint() { |
|
460 |
return isOptimistic() ? optimismInfo.optimisticAssumptions : null; |
|
461 |
} |
|
462 |
||
463 |
boolean isOptimistic() { |
|
464 |
return optimismInfo != null; |
|
465 |
} |
|
466 |
||
24725
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24719
diff
changeset
|
467 |
private MethodHandle createComposableInvoker(final boolean isConstructor) { |
24719 | 468 |
final MethodHandle handle = getInvokerOrConstructor(isConstructor); |
469 |
||
470 |
// If compiled function is not optimistic, it can't ever change its invoker/constructor, so just return them |
|
471 |
// directly. |
|
472 |
if(!isOptimistic()) { |
|
473 |
return handle; |
|
474 |
} |
|
475 |
||
476 |
// Otherwise, we need a new level of indirection; need to introduce a mutable call site that can relink itslef |
|
477 |
// to the compiled function's changed target whenever the optimistic assumptions are invalidated. |
|
478 |
final CallSite cs = new MutableCallSite(handle.type()); |
|
479 |
relinkComposableInvoker(cs, this, isConstructor); |
|
480 |
return cs.dynamicInvoker(); |
|
481 |
} |
|
482 |
private static void relinkComposableInvoker(final CallSite cs, final CompiledFunction inv, final boolean constructor) { |
|
483 |
final MethodHandle handle = inv.getInvokerOrConstructor(constructor); |
|
484 |
final SwitchPoint assumptions = inv.getOptimisticAssumptionsSwitchPoint(); |
|
485 |
final MethodHandle target; |
|
486 |
if(assumptions == null) { |
|
487 |
target = handle; |
|
488 |
} else { |
|
489 |
// This assertion can obviously fail in a multithreaded environment, as we can be in a situation where |
|
490 |
// one thread is in the middle of a deoptimizing compilation when we hit this and thus, it has invalidated |
|
491 |
// the old switch point, but hasn't created the new one yet. Note that the behavior of invalidating the old |
|
492 |
// switch point before recompilation, and only creating the new one after recompilation is by design. |
|
493 |
// TODO: We need to think about thread safety of CompiledFunction objects. |
|
494 |
assert !assumptions.hasBeenInvalidated(); |
|
495 |
final MethodHandle relink = MethodHandles.insertArguments(RELINK_COMPOSABLE_INVOKER, 0, cs, inv, constructor); |
|
496 |
target = assumptions.guardWithTest(handle, MethodHandles.foldArguments(cs.dynamicInvoker(), relink)); |
|
497 |
} |
|
498 |
cs.setTarget(target); |
|
499 |
} |
|
500 |
||
24725
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24719
diff
changeset
|
501 |
private MethodHandle getInvokerOrConstructor(final boolean selectCtor) { |
24719 | 502 |
return selectCtor ? getConstructor() : createInvokerForPessimisticCaller(); |
503 |
} |
|
504 |
||
505 |
MethodHandle createInvoker(final Class<?> callSiteReturnType, final int callerProgramPoint) { |
|
506 |
final boolean isOptimistic = isOptimistic(); |
|
507 |
MethodHandle handleRewriteException = isOptimistic ? createRewriteExceptionHandler() : null; |
|
508 |
||
509 |
MethodHandle inv = invoker; |
|
510 |
if(isValid(callerProgramPoint)) { |
|
511 |
inv = OptimisticReturnFilters.filterOptimisticReturnValue(inv, callSiteReturnType, callerProgramPoint); |
|
512 |
if(callSiteReturnType.isPrimitive() && handleRewriteException != null) { |
|
513 |
// because handleRewriteException always returns Object |
|
514 |
handleRewriteException = OptimisticReturnFilters.filterOptimisticReturnValue(handleRewriteException, |
|
515 |
callSiteReturnType, callerProgramPoint); |
|
516 |
} |
|
517 |
} else if(isOptimistic) { |
|
518 |
// Required so that rewrite exception has the same return type. It'd be okay to do it even if we weren't |
|
519 |
// optimistic, but it isn't necessary as the linker upstream will eventually convert the return type. |
|
520 |
inv = changeReturnType(inv, callSiteReturnType); |
|
521 |
} |
|
522 |
||
523 |
if(isOptimistic) { |
|
524 |
assert handleRewriteException != null; |
|
525 |
final MethodHandle typedHandleRewriteException = changeReturnType(handleRewriteException, inv.type().returnType()); |
|
526 |
if(USE_FAST_REWRITE) { |
|
527 |
return CatchExceptionCombinator.catchException(inv, RewriteException.class, typedHandleRewriteException); |
|
528 |
} |
|
529 |
return MH.catchException(inv, RewriteException.class, typedHandleRewriteException); |
|
530 |
} |
|
531 |
return inv; |
|
532 |
} |
|
533 |
||
534 |
private MethodHandle createRewriteExceptionHandler() { |
|
535 |
return MH.foldArguments(RESTOF_INVOKER, MH.insertArguments(HANDLE_REWRITE_EXCEPTION, 0, this, optimismInfo)); |
|
536 |
} |
|
537 |
||
24725
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24719
diff
changeset
|
538 |
private static MethodHandle changeReturnType(final MethodHandle mh, final Class<?> newReturnType) { |
24719 | 539 |
return Bootstrap.getLinkerServices().asType(mh, mh.type().changeReturnType(newReturnType)); |
540 |
} |
|
541 |
||
542 |
@SuppressWarnings("unused") |
|
543 |
private static MethodHandle handleRewriteException(final CompiledFunction function, final OptimismInfo oldOptimismInfo, final RewriteException re) { |
|
544 |
return function.handleRewriteException(oldOptimismInfo, re); |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
545 |
} |
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
546 |
|
24719 | 547 |
/** |
548 |
* Handles a {@link RewriteException} raised during the execution of this function by recompiling (if needed) the |
|
549 |
* function with an optimistic assumption invalidated at the program point indicated by the exception, and then |
|
550 |
* executing a rest-of method to complete the execution with the deoptimized version. |
|
551 |
* @param oldOptimismInfo the optimism info of this function. We must store it explicitly as a bound argument in the |
|
552 |
* method handle, otherwise it would be null for handling a rewrite exception in an outer invocation of a recursive |
|
553 |
* function when inner invocations of the function have completely deoptimized it. |
|
554 |
* @param re the rewrite exception that was raised |
|
555 |
* @return the method handle for the rest-of method, for folding composition. |
|
556 |
*/ |
|
557 |
private MethodHandle handleRewriteException(final OptimismInfo oldOptimismInfo, final RewriteException re) { |
|
558 |
final MethodType type = type(); |
|
559 |
// Compiler needs a call site type as its input, which always has a callee parameter, so we must add it if |
|
560 |
// this function doesn't have a callee parameter. |
|
561 |
final MethodType callSiteType = type.parameterType(0) == ScriptFunction.class ? type : type.insertParameterTypes(0, ScriptFunction.class); |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
562 |
|
24719 | 563 |
final FunctionNode fn = oldOptimismInfo.recompile(callSiteType, re); |
564 |
LOG.info(" RewriteException ", re.getMessageShort()); |
|
565 |
||
566 |
// It didn't necessarily recompile, e.g. for an outer invocation of a recursive function if we already |
|
567 |
// recompiled a deoptimized version for an inner invocation. |
|
568 |
||
569 |
final boolean isOptimistic; |
|
570 |
if (fn != null) { |
|
571 |
//is recompiled |
|
572 |
assert optimismInfo == oldOptimismInfo; |
|
573 |
isOptimistic = fn.isOptimistic(); |
|
24725
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24719
diff
changeset
|
574 |
if (LOG.isEnabled()) { |
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24719
diff
changeset
|
575 |
LOG.info("Recompiled '", fn.getName(), "' (", Debug.id(this), ")", isOptimistic ? " remains optimistic." : " is no longer optimistic."); |
7bb1f687a852
8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents:
24719
diff
changeset
|
576 |
} |
24719 | 577 |
final MethodHandle newInvoker = oldOptimismInfo.data.lookup(fn); |
578 |
invoker = newInvoker.asType(type.changeReturnType(newInvoker.type().returnType())); |
|
579 |
constructor = null; // Will be regenerated when needed |
|
580 |
// Note that we only adjust the switch point after we set the invoker/constructor. This is important. |
|
581 |
if(isOptimistic) { |
|
582 |
// Otherwise, set a new switch point. |
|
583 |
oldOptimismInfo.newOptimisticAssumptions(); |
|
584 |
} else { |
|
585 |
// If we got to a point where we no longer have optimistic assumptions, let the optimism info go. |
|
586 |
optimismInfo = null; |
|
587 |
} |
|
588 |
} else { |
|
589 |
isOptimistic = isOptimistic(); |
|
590 |
assert !isOptimistic || optimismInfo == oldOptimismInfo; |
|
591 |
} |
|
592 |
||
593 |
final MethodHandle restOf = changeReturnType(oldOptimismInfo.compileRestOfMethod(callSiteType, re), Object.class); |
|
594 |
// If rest-of is itself optimistic, we must make sure that we can repeat a deoptimization if it, too hits an exception. |
|
595 |
return isOptimistic ? MH.catchException(restOf, RewriteException.class, createRewriteExceptionHandler()) : restOf; |
|
596 |
} |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
597 |
|
24719 | 598 |
private static class OptimismInfo { |
599 |
// TODO: this is pointing to its owning ScriptFunctionData. Re-evaluate if that's okay. |
|
600 |
private final RecompilableScriptFunctionData data; |
|
601 |
private final Map<Integer, Type> invalidatedProgramPoints = new TreeMap<>(); |
|
602 |
private SwitchPoint optimisticAssumptions; |
|
603 |
||
604 |
OptimismInfo(final RecompilableScriptFunctionData data) { |
|
605 |
this.data = data; |
|
606 |
newOptimisticAssumptions(); |
|
607 |
} |
|
608 |
||
609 |
private void newOptimisticAssumptions() { |
|
610 |
optimisticAssumptions = new SwitchPoint(); |
|
611 |
} |
|
612 |
||
613 |
FunctionNode recompile(final MethodType callSiteType, final RewriteException e) { |
|
614 |
final Type retType = e.getReturnType(); |
|
615 |
final Type previousFailedType = invalidatedProgramPoints.put(e.getProgramPoint(), retType); |
|
616 |
if (previousFailedType != null && !previousFailedType.narrowerThan(retType)) { |
|
617 |
final StackTraceElement[] stack = e.getStackTrace(); |
|
618 |
final String functionId = stack.length == 0 ? data.getName() : (stack[0].getClassName() + "." + stack[0].getMethodName()); |
|
619 |
LOG.info("RewriteException for an already invalidated program point ", e.getProgramPoint(), " in ", functionId, ". This is okay for a recursive function invocation, but a bug otherwise."); |
|
620 |
return null; |
|
621 |
} |
|
622 |
SwitchPoint.invalidateAll(new SwitchPoint[] { optimisticAssumptions }); |
|
623 |
return data.compile(callSiteType, invalidatedProgramPoints, "Deoptimizing recompilation"); |
|
624 |
} |
|
625 |
||
626 |
MethodHandle compileRestOfMethod(final MethodType callSiteType, final RewriteException e) { |
|
627 |
final int[] prevEntryPoints = e.getPreviousContinuationEntryPoints(); |
|
628 |
final int[] entryPoints; |
|
629 |
if(prevEntryPoints == null) { |
|
630 |
entryPoints = new int[1]; |
|
631 |
} else { |
|
632 |
final int l = prevEntryPoints.length; |
|
633 |
entryPoints = new int[l + 1]; |
|
634 |
System.arraycopy(prevEntryPoints, 0, entryPoints, 1, l); |
|
635 |
} |
|
636 |
entryPoints[0] = e.getProgramPoint(); |
|
637 |
return data.compileRestOfMethod(callSiteType, invalidatedProgramPoints, entryPoints); |
|
638 |
} |
|
639 |
} |
|
640 |
||
641 |
@SuppressWarnings("unused") |
|
642 |
private static Object newFilter(final Object result, final Object allocation) { |
|
643 |
return (result instanceof ScriptObject || !JSType.isPrimitive(result))? result : allocation; |
|
644 |
} |
|
645 |
||
646 |
private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) { |
|
647 |
return MH.findStatic(MethodHandles.lookup(), CompiledFunction.class, name, MH.type(rtype, types)); |
|
648 |
} |
|
16523
af8b30edebce
8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents:
diff
changeset
|
649 |
} |