author | sundar |
Thu, 11 Jul 2013 22:58:37 +0530 | |
changeset 18868 | f5359cad148c |
parent 18614 | addca7a10167 |
child 19456 | 8cc345d620c8 |
permissions | -rw-r--r-- |
16147 | 1 |
/* |
16151 | 2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
16147 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.nashorn.internal.runtime; |
|
27 |
||
28 |
import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCallNoLookup; |
|
29 |
import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; |
|
30 |
import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; |
|
16277 | 31 |
import static jdk.nashorn.internal.lookup.Lookup.MH; |
16147 | 32 |
|
33 |
import java.lang.invoke.MethodHandle; |
|
34 |
import java.lang.invoke.MethodHandles; |
|
35 |
import java.lang.invoke.MethodType; |
|
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:
16277
diff
changeset
|
36 |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
16233
diff
changeset
|
37 |
import jdk.internal.dynalink.CallSiteDescriptor; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
16233
diff
changeset
|
38 |
import jdk.internal.dynalink.linker.GuardedInvocation; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
16233
diff
changeset
|
39 |
import jdk.internal.dynalink.linker.LinkRequest; |
16147 | 40 |
import jdk.nashorn.internal.codegen.CompilerConstants.Call; |
16277 | 41 |
import jdk.nashorn.internal.lookup.MethodHandleFactory; |
16147 | 42 |
import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; |
43 |
import jdk.nashorn.internal.runtime.linker.NashornGuards; |
|
44 |
||
45 |
/** |
|
46 |
* Runtime representation of a JavaScript function. |
|
47 |
*/ |
|
48 |
public abstract class ScriptFunction extends ScriptObject { |
|
49 |
||
50 |
/** Method handle for prototype getter for this ScriptFunction */ |
|
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:
16277
diff
changeset
|
51 |
public static final MethodHandle G$PROTOTYPE = findOwnMH("G$prototype", Object.class, Object.class); |
16147 | 52 |
|
53 |
/** Method handle for prototype setter for this ScriptFunction */ |
|
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:
16277
diff
changeset
|
54 |
public static final MethodHandle S$PROTOTYPE = findOwnMH("S$prototype", void.class, Object.class, Object.class); |
16147 | 55 |
|
56 |
/** Method handle for length getter for this ScriptFunction */ |
|
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:
16277
diff
changeset
|
57 |
public static final MethodHandle G$LENGTH = findOwnMH("G$length", int.class, Object.class); |
16147 | 58 |
|
59 |
/** Method handle for name getter for this ScriptFunction */ |
|
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:
16277
diff
changeset
|
60 |
public static final MethodHandle G$NAME = findOwnMH("G$name", Object.class, Object.class); |
16147 | 61 |
|
62 |
/** Method handle for allocate function for this ScriptFunction */ |
|
16228 | 63 |
static final MethodHandle ALLOCATE = findOwnMH("allocate", Object.class); |
16147 | 64 |
|
16207
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
65 |
private static final MethodHandle WRAPFILTER = findOwnMH("wrapFilter", Object.class, Object.class); |
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
66 |
|
16147 | 67 |
/** method handle to scope getter for this ScriptFunction */ |
68 |
public static final Call GET_SCOPE = virtualCallNoLookup(ScriptFunction.class, "getScope", ScriptObject.class); |
|
69 |
||
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:
16277
diff
changeset
|
70 |
private static final MethodHandle IS_FUNCTION_MH = findOwnMH("isFunctionMH", boolean.class, Object.class, ScriptFunctionData.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:
16277
diff
changeset
|
71 |
|
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:
16277
diff
changeset
|
72 |
private static final MethodHandle IS_NONSTRICT_FUNCTION = findOwnMH("isNonStrictFunction", boolean.class, Object.class, Object.class, ScriptFunctionData.class); |
16147 | 73 |
|
18868
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
74 |
private static final MethodHandle ADD_ZEROTH_ELEMENT = findOwnMH("addZerothElement", Object[].class, Object[].class, Object.class); |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
75 |
|
16147 | 76 |
/** The parent scope. */ |
77 |
private final ScriptObject scope; |
|
78 |
||
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:
16277
diff
changeset
|
79 |
private final ScriptFunctionData data; |
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:
16277
diff
changeset
|
80 |
|
16147 | 81 |
/** |
82 |
* Constructor |
|
83 |
* |
|
16233
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
84 |
* @param name function name |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
85 |
* @param methodHandle method handle to function (if specializations are present, assumed to be most generic) |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
86 |
* @param map property map |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
87 |
* @param scope scope |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
88 |
* @param specs specialized version of this function - other method handles |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
89 |
* @param strict is this a strict mode function? |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
90 |
* @param builtin is this a built in function? |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
91 |
* @param isConstructor is this a constructor? |
16147 | 92 |
*/ |
93 |
protected ScriptFunction( |
|
94 |
final String name, |
|
95 |
final MethodHandle methodHandle, |
|
96 |
final PropertyMap map, |
|
97 |
final ScriptObject scope, |
|
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
98 |
final MethodHandle[] specs, |
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
99 |
final boolean strict, |
16228 | 100 |
final boolean builtin, |
101 |
final boolean isConstructor) { |
|
16206
83069fa0935b
8006529: Methods always get callee - it should be conditional
attila
parents:
16202
diff
changeset
|
102 |
|
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:
16277
diff
changeset
|
103 |
this(new FinalScriptFunctionData(name, methodHandle, specs, strict, builtin, isConstructor), map, scope); |
16147 | 104 |
} |
105 |
||
106 |
/** |
|
107 |
* Constructor |
|
108 |
* |
|
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
109 |
* @param data static function data |
16147 | 110 |
* @param map property map |
111 |
* @param scope scope |
|
112 |
*/ |
|
113 |
protected ScriptFunction( |
|
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
114 |
final ScriptFunctionData data, |
16147 | 115 |
final PropertyMap map, |
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
116 |
final ScriptObject scope) { |
16147 | 117 |
|
118 |
super(map); |
|
119 |
||
120 |
if (Context.DEBUG) { |
|
121 |
constructorCount++; |
|
122 |
} |
|
123 |
||
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:
16277
diff
changeset
|
124 |
this.data = data; |
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:
16277
diff
changeset
|
125 |
this.scope = scope; |
16147 | 126 |
} |
127 |
||
128 |
@Override |
|
129 |
public String getClassName() { |
|
130 |
return "Function"; |
|
131 |
} |
|
132 |
||
133 |
/** |
|
134 |
* ECMA 15.3.5.3 [[HasInstance]] (V) |
|
135 |
* Step 3 if "prototype" value is not an Object, throw TypeError |
|
136 |
*/ |
|
137 |
@Override |
|
138 |
public boolean isInstance(final ScriptObject instance) { |
|
16228 | 139 |
final Object basePrototype = getTargetFunction().getPrototype(); |
140 |
if (!(basePrototype instanceof ScriptObject)) { |
|
16256
f2d9a0c49914
8007002: Replace implicit exception throwing methods with explicit throws - simplify control flow and remove useless code
lagergren
parents:
16234
diff
changeset
|
141 |
throw typeError("prototype.not.an.object", ScriptRuntime.safeToString(getTargetFunction()), ScriptRuntime.safeToString(basePrototype)); |
16147 | 142 |
} |
143 |
||
144 |
for (ScriptObject proto = instance.getProto(); proto != null; proto = proto.getProto()) { |
|
16228 | 145 |
if (proto == basePrototype) { |
16147 | 146 |
return true; |
147 |
} |
|
148 |
} |
|
149 |
||
150 |
return false; |
|
151 |
} |
|
152 |
||
153 |
/** |
|
16228 | 154 |
* Returns the target function for this function. If the function was not created using |
155 |
* {@link #makeBoundFunction(Object, Object[])}, its target function is itself. If it is bound, its target function |
|
156 |
* is the target function of the function it was made from (therefore, the target function is always the final, |
|
157 |
* unbound recipient of the calls). |
|
158 |
* @return the target function for this function. |
|
16147 | 159 |
*/ |
16228 | 160 |
protected ScriptFunction getTargetFunction() { |
161 |
return this; |
|
162 |
} |
|
163 |
||
164 |
boolean isBoundFunction() { |
|
165 |
return getTargetFunction() != this; |
|
16147 | 166 |
} |
167 |
||
168 |
/** |
|
169 |
* Set the arity of this ScriptFunction |
|
170 |
* @param arity arity |
|
171 |
*/ |
|
172 |
public final void setArity(final int arity) { |
|
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
173 |
data.setArity(arity); |
16147 | 174 |
} |
175 |
||
176 |
/** |
|
177 |
* Is this a ECMAScript 'use strict' function? |
|
178 |
* @return true if function is in strict mode |
|
179 |
*/ |
|
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
180 |
public boolean isStrict() { |
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
181 |
return data.isStrict(); |
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
182 |
} |
16147 | 183 |
|
184 |
/** |
|
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
185 |
* Returns true if this is a non-strict, non-built-in function that requires non-primitive this argument |
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
186 |
* according to ECMA 10.4.3. |
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
187 |
* @return true if this argument must be an object |
16186
91bd9d2aa2f5
8006570: This-value for non-strict functions should be converted to object
hannesw
parents:
16173
diff
changeset
|
188 |
*/ |
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
189 |
public boolean needsWrappedThis() { |
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
190 |
return data.needsWrappedThis(); |
16186
91bd9d2aa2f5
8006570: This-value for non-strict functions should be converted to object
hannesw
parents:
16173
diff
changeset
|
191 |
} |
91bd9d2aa2f5
8006570: This-value for non-strict functions should be converted to object
hannesw
parents:
16173
diff
changeset
|
192 |
|
91bd9d2aa2f5
8006570: This-value for non-strict functions should be converted to object
hannesw
parents:
16173
diff
changeset
|
193 |
/** |
16147 | 194 |
* Execute this script function. |
195 |
* @param self Target object. |
|
196 |
* @param arguments Call arguments. |
|
197 |
* @return ScriptFunction result. |
|
198 |
* @throws Throwable if there is an exception/error with the invocation or thrown from it |
|
199 |
*/ |
|
16232
efd57dd90de6
8008197: Cross script engine function calls do not work as expected
sundar
parents:
16228
diff
changeset
|
200 |
Object invoke(final Object self, final Object... arguments) throws Throwable { |
16147 | 201 |
if (Context.DEBUG) { |
202 |
invokes++; |
|
203 |
} |
|
16228 | 204 |
return data.invoke(this, self, arguments); |
16147 | 205 |
} |
206 |
||
207 |
/** |
|
18614 | 208 |
* Execute this script function as a constructor. |
209 |
* @param arguments Call arguments. |
|
210 |
* @return Newly constructed result. |
|
211 |
* @throws Throwable if there is an exception/error with the invocation or thrown from it |
|
212 |
*/ |
|
213 |
Object construct(final Object... arguments) throws Throwable { |
|
214 |
return data.construct(this, arguments); |
|
215 |
} |
|
216 |
||
217 |
/** |
|
16147 | 218 |
* Allocate function. Called from generated {@link ScriptObject} code |
219 |
* for allocation as a factory method |
|
220 |
* |
|
221 |
* @return a new instance of the {@link ScriptObject} whose allocator this is |
|
222 |
*/ |
|
16228 | 223 |
@SuppressWarnings("unused") |
224 |
private Object allocate() { |
|
16147 | 225 |
if (Context.DEBUG) { |
226 |
allocations++; |
|
227 |
} |
|
16228 | 228 |
assert !isBoundFunction(); // allocate never invoked on bound functions |
16147 | 229 |
|
16228 | 230 |
final ScriptObject object = data.allocate(); |
16147 | 231 |
|
232 |
if (object != null) { |
|
17252
9aeb443c4740
8006559: Octane:pdfjs leaks memory, runs slower iteration to iteration
hannesw
parents:
16523
diff
changeset
|
233 |
Object prototype = getPrototype(); |
16147 | 234 |
if (prototype instanceof ScriptObject) { |
235 |
object.setProto((ScriptObject)prototype); |
|
236 |
} |
|
237 |
||
238 |
if (object.getProto() == null) { |
|
239 |
object.setProto(getObjectPrototype()); |
|
240 |
} |
|
241 |
} |
|
242 |
||
243 |
return object; |
|
244 |
} |
|
245 |
||
246 |
/** |
|
247 |
* Return Object.prototype - used by "allocate" |
|
248 |
* @return Object.prototype |
|
249 |
*/ |
|
250 |
protected abstract ScriptObject getObjectPrototype(); |
|
251 |
||
252 |
/** |
|
16228 | 253 |
* Creates a version of this function bound to a specific "self" and other arguments, as per |
254 |
* {@code Function.prototype.bind} functionality in ECMAScript 5.1 section 15.3.4.5. |
|
255 |
* @param self the self to bind to this function. Can be null (in which case, null is bound as this). |
|
256 |
* @param args additional arguments to bind to this function. Can be null or empty to not bind additional arguments. |
|
257 |
* @return a function with the specified self and parameters bound. |
|
16147 | 258 |
*/ |
16233
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
259 |
protected ScriptFunction makeBoundFunction(final Object self, final Object[] args) { |
16228 | 260 |
return makeBoundFunction(data.makeBoundFunctionData(this, self, args)); |
261 |
} |
|
16147 | 262 |
|
16233
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
263 |
/** |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
264 |
* Create a version of this function as in {@link ScriptFunction#makeBoundFunction(Object, Object[])}, |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
265 |
* but using a {@link ScriptFunctionData} for the bound data. |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
266 |
* |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
267 |
* @param boundData ScriptFuntionData for the bound function |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
268 |
* @return a function with the bindings performed according to the given data |
95d3e01c04c3
8008199: Lazy compilation and trampoline implementation
lagergren
parents:
16232
diff
changeset
|
269 |
*/ |
16228 | 270 |
protected abstract ScriptFunction makeBoundFunction(ScriptFunctionData boundData); |
16147 | 271 |
|
272 |
@Override |
|
273 |
public final String safeToString() { |
|
274 |
return toSource(); |
|
275 |
} |
|
276 |
||
277 |
@Override |
|
278 |
public String toString() { |
|
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
279 |
return data.toString(); |
16147 | 280 |
} |
281 |
||
282 |
/** |
|
283 |
* Get this function as a String containing its source code. If no source code |
|
284 |
* exists in this ScriptFunction, its contents will be displayed as {@code [native code]} |
|
285 |
* @return string representation of this function's source |
|
286 |
*/ |
|
287 |
public final String toSource() { |
|
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
288 |
return data.toSource(); |
16147 | 289 |
} |
290 |
||
291 |
/** |
|
292 |
* Get the prototype object for this function |
|
293 |
* @return prototype |
|
294 |
*/ |
|
17252
9aeb443c4740
8006559: Octane:pdfjs leaks memory, runs slower iteration to iteration
hannesw
parents:
16523
diff
changeset
|
295 |
public abstract Object getPrototype(); |
16147 | 296 |
|
297 |
/** |
|
298 |
* Set the prototype object for this function |
|
299 |
* @param prototype new prototype object |
|
300 |
*/ |
|
17252
9aeb443c4740
8006559: Octane:pdfjs leaks memory, runs slower iteration to iteration
hannesw
parents:
16523
diff
changeset
|
301 |
public abstract void setPrototype(Object prototype); |
16147 | 302 |
|
303 |
/** |
|
304 |
* Return the most appropriate invoke handle if there are specializations |
|
305 |
* @param type most specific method type to look for invocation with |
|
17252
9aeb443c4740
8006559: Octane:pdfjs leaks memory, runs slower iteration to iteration
hannesw
parents:
16523
diff
changeset
|
306 |
* @param args args for trampoline invocation |
16147 | 307 |
* @return invoke method handle |
308 |
*/ |
|
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:
16277
diff
changeset
|
309 |
private MethodHandle getBestInvoker(final MethodType type, final Object[] args) { |
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:
16277
diff
changeset
|
310 |
return data.getBestInvoker(type, args); |
16147 | 311 |
} |
312 |
||
313 |
/** |
|
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:
16277
diff
changeset
|
314 |
* Return the most appropriate invoke handle if there are specializations |
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:
16277
diff
changeset
|
315 |
* @param type most specific method type to look for invocation with |
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:
16277
diff
changeset
|
316 |
* @return invoke method handle |
16147 | 317 |
*/ |
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:
16277
diff
changeset
|
318 |
public MethodHandle getBestInvoker(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:
16277
diff
changeset
|
319 |
return getBestInvoker(type, null); |
16147 | 320 |
} |
321 |
||
322 |
/** |
|
323 |
* Return the invoke handle bound to a given ScriptObject self reference. |
|
324 |
* If callee parameter is required result is rebound to this. |
|
325 |
* |
|
326 |
* @param self self reference |
|
327 |
* @return bound invoke handle |
|
328 |
*/ |
|
329 |
public final MethodHandle getBoundInvokeHandle(final ScriptObject self) { |
|
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:
16277
diff
changeset
|
330 |
return MH.bindTo(bindToCalleeIfNeeded(data.getGenericInvoker()), self); |
16147 | 331 |
} |
332 |
||
16225
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
333 |
/** |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
334 |
* Bind the method handle to this {@code ScriptFunction} instance if it needs a callee parameter. If this function's |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
335 |
* method handles don't have a callee parameter, the handle is returned unchanged. |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
336 |
* @param methodHandle the method handle to potentially bind to this function instance. |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
337 |
* @return the potentially bound method handle |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
338 |
*/ |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
339 |
private MethodHandle bindToCalleeIfNeeded(final MethodHandle methodHandle) { |
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:
16277
diff
changeset
|
340 |
return ScriptFunctionData.needsCallee(methodHandle) ? MH.bindTo(methodHandle, this) : methodHandle; |
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:
16277
diff
changeset
|
341 |
|
16225
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
342 |
} |
16147 | 343 |
|
344 |
/** |
|
345 |
* Get the name for this function |
|
346 |
* @return the name |
|
347 |
*/ |
|
348 |
public final String getName() { |
|
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
349 |
return data.getName(); |
16147 | 350 |
} |
351 |
||
352 |
||
353 |
/** |
|
354 |
* Get the scope for this function |
|
355 |
* @return the scope |
|
356 |
*/ |
|
357 |
public final ScriptObject getScope() { |
|
358 |
return scope; |
|
359 |
} |
|
360 |
||
361 |
/** |
|
362 |
* Prototype getter for this ScriptFunction - follows the naming convention |
|
363 |
* used by Nasgen and the code generator |
|
364 |
* |
|
365 |
* @param self self reference |
|
366 |
* @return self's prototype |
|
367 |
*/ |
|
368 |
public static Object G$prototype(final Object self) { |
|
369 |
return (self instanceof ScriptFunction) ? |
|
370 |
((ScriptFunction)self).getPrototype() : |
|
371 |
UNDEFINED; |
|
372 |
} |
|
373 |
||
374 |
/** |
|
375 |
* Prototype setter for this ScriptFunction - follows the naming convention |
|
376 |
* used by Nasgen and the code generator |
|
377 |
* |
|
378 |
* @param self self reference |
|
379 |
* @param prototype prototype to set |
|
380 |
*/ |
|
381 |
public static void S$prototype(final Object self, final Object prototype) { |
|
382 |
if (self instanceof ScriptFunction) { |
|
383 |
((ScriptFunction)self).setPrototype(prototype); |
|
384 |
} |
|
385 |
} |
|
386 |
||
387 |
/** |
|
388 |
* Length getter - ECMA 15.3.3.2: Function.length |
|
389 |
* @param self self reference |
|
390 |
* @return length |
|
391 |
*/ |
|
392 |
public static int G$length(final Object self) { |
|
393 |
if (self instanceof ScriptFunction) { |
|
16228 | 394 |
return ((ScriptFunction)self).data.getArity(); |
16147 | 395 |
} |
396 |
||
397 |
return 0; |
|
398 |
} |
|
399 |
||
400 |
/** |
|
401 |
* Name getter - ECMA Function.name |
|
402 |
* @param self self refence |
|
403 |
* @return the name, or undefined if none |
|
404 |
*/ |
|
405 |
public static Object G$name(final Object self) { |
|
406 |
if (self instanceof ScriptFunction) { |
|
407 |
return ((ScriptFunction)self).getName(); |
|
408 |
} |
|
409 |
||
410 |
return UNDEFINED; |
|
411 |
} |
|
412 |
||
413 |
/** |
|
414 |
* Get the prototype for this ScriptFunction |
|
415 |
* @param constructor constructor |
|
416 |
* @return prototype, or null if given constructor is not a ScriptFunction |
|
417 |
*/ |
|
418 |
public static ScriptObject getPrototype(final Object constructor) { |
|
419 |
if (constructor instanceof ScriptFunction) { |
|
420 |
final Object proto = ((ScriptFunction)constructor).getPrototype(); |
|
421 |
if (proto instanceof ScriptObject) { |
|
422 |
return (ScriptObject)proto; |
|
423 |
} |
|
424 |
} |
|
425 |
||
426 |
return null; |
|
427 |
} |
|
428 |
||
429 |
// These counters are updated only in debug mode. |
|
430 |
private static int constructorCount; |
|
431 |
private static int invokes; |
|
432 |
private static int allocations; |
|
433 |
||
434 |
/** |
|
435 |
* @return the constructorCount |
|
436 |
*/ |
|
437 |
public static int getConstructorCount() { |
|
438 |
return constructorCount; |
|
439 |
} |
|
440 |
||
441 |
/** |
|
442 |
* @return the invokes |
|
443 |
*/ |
|
444 |
public static int getInvokes() { |
|
445 |
return invokes; |
|
446 |
} |
|
447 |
||
448 |
/** |
|
449 |
* @return the allocations |
|
450 |
*/ |
|
451 |
public static int getAllocations() { |
|
452 |
return allocations; |
|
453 |
} |
|
454 |
||
455 |
@Override |
|
456 |
protected GuardedInvocation findNewMethod(final CallSiteDescriptor desc) { |
|
457 |
final MethodType type = desc.getMethodType(); |
|
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:
16277
diff
changeset
|
458 |
return new GuardedInvocation(pairArguments(data.getBestConstructor(type.changeParameterType(0, ScriptFunction.class), null), type), null, getFunctionGuard(this)); |
16147 | 459 |
} |
460 |
||
16207
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
461 |
@SuppressWarnings("unused") |
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
462 |
private static Object wrapFilter(final Object obj) { |
16228 | 463 |
if (obj instanceof ScriptObject || !ScriptFunctionData.isPrimitiveThis(obj)) { |
16207
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
464 |
return obj; |
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
465 |
} |
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:
16277
diff
changeset
|
466 |
return ((GlobalObject)Context.getGlobalTrusted()).wrapAsObject(obj); |
16207
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
467 |
} |
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
468 |
|
16147 | 469 |
/** |
470 |
* dyn:call call site signature: (callee, thiz, [args...]) |
|
16225
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
471 |
* generated method signature: (callee, thiz, [args...]) |
16147 | 472 |
* |
473 |
* cases: |
|
474 |
* (a) method has callee parameter |
|
475 |
* (1) for local/scope calls, we just bind thiz and drop the second argument. |
|
476 |
* (2) for normal this-calls, we have to swap thiz and callee to get matching signatures. |
|
477 |
* (b) method doesn't have callee parameter (builtin functions) |
|
478 |
* (3) for local/scope calls, bind thiz and drop both callee and thiz. |
|
479 |
* (4) for normal this-calls, drop callee. |
|
480 |
*/ |
|
481 |
@Override |
|
16195
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
482 |
protected GuardedInvocation findCallMethod(final CallSiteDescriptor desc, final LinkRequest request) { |
16147 | 483 |
final MethodType type = desc.getMethodType(); |
484 |
||
16195
3f6c0ab2597a
8006766: Array-like access to characters of a string is slow
hannesw
parents:
16188
diff
changeset
|
485 |
if (request.isCallSiteUnstable()) { |
16147 | 486 |
// (this, callee, args...) => (this, callee, args[]) |
487 |
final MethodHandle collector = MH.asCollector(ScriptRuntime.APPLY.methodHandle(), Object[].class, |
|
488 |
type.parameterCount() - 2); |
|
489 |
||
16225
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
490 |
// If call site is statically typed to take a ScriptFunction, we don't need a guard, otherwise we need a |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
491 |
// generic "is this a ScriptFunction?" guard. |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
492 |
return new GuardedInvocation(collector, ScriptFunction.class.isAssignableFrom(desc.getMethodType().parameterType(0)) |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
493 |
? null : NashornGuards.getScriptFunctionGuard()); |
16147 | 494 |
} |
495 |
||
496 |
MethodHandle boundHandle; |
|
16207
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
497 |
MethodHandle guard = null; |
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
498 |
|
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
499 |
if (data.needsCallee()) { |
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:
16277
diff
changeset
|
500 |
final MethodHandle callHandle = getBestInvoker(type, request.getArguments()); |
16225
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
501 |
if (NashornCallSiteDescriptor.isScope(desc)) { |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
502 |
// Make a handle that drops the passed "this" argument and substitutes either Global or Undefined |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
503 |
// (callee, this, args...) => (callee, args...) |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
504 |
boundHandle = MH.insertArguments(callHandle, 1, needsWrappedThis() ? Context.getGlobalTrusted() : ScriptRuntime.UNDEFINED); |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
505 |
// (callee, args...) => (callee, [this], args...) |
16147 | 506 |
boundHandle = MH.dropArguments(boundHandle, 1, Object.class); |
507 |
} else { |
|
16225
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
508 |
// It's already (callee, this, args...), just what we need |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
509 |
boundHandle = callHandle; |
16207
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
510 |
|
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
511 |
// For non-strict functions, check whether this-object is primitive type. |
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
512 |
// If so add a to-object-wrapper argument filter. |
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
513 |
// Else install a guard that will trigger a relink when the argument becomes primitive. |
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
514 |
if (needsWrappedThis()) { |
16228 | 515 |
if (ScriptFunctionData.isPrimitiveThis(request.getArguments()[1])) { |
16207
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
516 |
boundHandle = MH.filterArguments(boundHandle, 1, WRAPFILTER); |
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
517 |
} else { |
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:
16277
diff
changeset
|
518 |
guard = getNonStrictFunctionGuard(this); |
16207
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
519 |
} |
ed4aec2d599c
8007060: Primitive wrap filter throws ClassCastException in test262parallel
hannesw
parents:
16206
diff
changeset
|
520 |
} |
16147 | 521 |
} |
522 |
} else { |
|
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:
16277
diff
changeset
|
523 |
final MethodHandle callHandle = getBestInvoker(type.dropParameterTypes(0, 1), request.getArguments()); |
16225
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
524 |
if (NashornCallSiteDescriptor.isScope(desc)) { |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
525 |
// Make a handle that drops the passed "this" argument and substitutes either Global or Undefined |
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
526 |
// (this, args...) => (args...) |
16216
46ed48fd84d3
8007273: Creation of ScriptFunctions can be refactored
hannesw
parents:
16210
diff
changeset
|
527 |
boundHandle = MH.bindTo(callHandle, needsWrappedThis() ? Context.getGlobalTrusted() : ScriptRuntime.UNDEFINED); |
16225
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
528 |
// (args...) => ([callee], [this], args...) |
16147 | 529 |
boundHandle = MH.dropArguments(boundHandle, 0, Object.class, Object.class); |
530 |
} else { |
|
16225
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
531 |
// (this, args...) => ([callee], this, args...) |
16147 | 532 |
boundHandle = MH.dropArguments(callHandle, 0, Object.class); |
533 |
} |
|
534 |
} |
|
535 |
||
536 |
boundHandle = pairArguments(boundHandle, type); |
|
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:
16277
diff
changeset
|
537 |
|
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:
16277
diff
changeset
|
538 |
return new GuardedInvocation(boundHandle, guard == null ? getFunctionGuard(this) : guard); |
16188 | 539 |
} |
16147 | 540 |
|
541 |
/** |
|
542 |
* Used for noSuchMethod/noSuchProperty and JSAdapter hooks. |
|
543 |
* |
|
544 |
* These don't want a callee parameter, so bind that. Name binding is optional. |
|
545 |
*/ |
|
546 |
MethodHandle getCallMethodHandle(final MethodType type, final String bindName) { |
|
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:
16277
diff
changeset
|
547 |
return pairArguments(bindToNameIfNeeded(bindToCalleeIfNeeded(getBestInvoker(type, null)), bindName), type); |
16225
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
548 |
} |
16147 | 549 |
|
16225
81d58c2b9fcf
8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents:
16216
diff
changeset
|
550 |
private static MethodHandle bindToNameIfNeeded(final MethodHandle methodHandle, final String bindName) { |
18868
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
551 |
if (bindName == null) { |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
552 |
return methodHandle; |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
553 |
} else { |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
554 |
// if it is vararg method, we need to extend argument array with |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
555 |
// a new zeroth element that is set to bindName value. |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
556 |
final MethodType methodType = methodHandle.type(); |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
557 |
final int parameterCount = methodType.parameterCount(); |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
558 |
final boolean isVarArg = parameterCount > 0 && methodType.parameterType(parameterCount - 1).isArray(); |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
559 |
|
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
560 |
if (isVarArg) { |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
561 |
return MH.filterArguments(methodHandle, 1, MH.insertArguments(ADD_ZEROTH_ELEMENT, 1, bindName)); |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
562 |
} else { |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
563 |
return MH.insertArguments(methodHandle, 1, bindName); |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
564 |
} |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
565 |
} |
16147 | 566 |
} |
567 |
||
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:
16277
diff
changeset
|
568 |
/** |
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:
16277
diff
changeset
|
569 |
* Get the guard that checks if a {@link ScriptFunction} is equal to |
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:
16277
diff
changeset
|
570 |
* a known ScriptFunction, using reference comparison |
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:
16277
diff
changeset
|
571 |
* |
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:
16277
diff
changeset
|
572 |
* @param function The ScriptFunction to check against. This will be bound to the guard method handle |
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:
16277
diff
changeset
|
573 |
* |
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:
16277
diff
changeset
|
574 |
* @return method handle for guard |
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:
16277
diff
changeset
|
575 |
*/ |
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:
16277
diff
changeset
|
576 |
private static MethodHandle getFunctionGuard(final ScriptFunction function) { |
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:
16277
diff
changeset
|
577 |
assert function.data != 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:
16277
diff
changeset
|
578 |
return MH.insertArguments(IS_FUNCTION_MH, 1, function.data); |
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:
16277
diff
changeset
|
579 |
} |
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:
16277
diff
changeset
|
580 |
|
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:
16277
diff
changeset
|
581 |
/** |
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:
16277
diff
changeset
|
582 |
* Get a guard that checks if a {@link ScriptFunction} is equal to |
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:
16277
diff
changeset
|
583 |
* a known ScriptFunction using reference comparison, and whether the type of |
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:
16277
diff
changeset
|
584 |
* the second argument (this-object) is not a JavaScript primitive 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:
16277
diff
changeset
|
585 |
* |
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:
16277
diff
changeset
|
586 |
* @param function The ScriptFunction to check against. This will be bound to the guard method handle |
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:
16277
diff
changeset
|
587 |
* |
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:
16277
diff
changeset
|
588 |
* @return method handle for guard |
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:
16277
diff
changeset
|
589 |
*/ |
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:
16277
diff
changeset
|
590 |
private static MethodHandle getNonStrictFunctionGuard(final ScriptFunction function) { |
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:
16277
diff
changeset
|
591 |
assert function.data != 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:
16277
diff
changeset
|
592 |
return MH.insertArguments(IS_NONSTRICT_FUNCTION, 2, function.data); |
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:
16277
diff
changeset
|
593 |
} |
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:
16277
diff
changeset
|
594 |
|
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:
16277
diff
changeset
|
595 |
@SuppressWarnings("unused") |
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:
16277
diff
changeset
|
596 |
private static boolean isFunctionMH(final Object self, final ScriptFunctionData data) { |
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:
16277
diff
changeset
|
597 |
return self instanceof ScriptFunction && ((ScriptFunction)self).data == data; |
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:
16277
diff
changeset
|
598 |
} |
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:
16277
diff
changeset
|
599 |
|
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:
16277
diff
changeset
|
600 |
@SuppressWarnings("unused") |
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:
16277
diff
changeset
|
601 |
private static boolean isNonStrictFunction(final Object self, final Object arg, final ScriptFunctionData data) { |
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:
16277
diff
changeset
|
602 |
return self instanceof ScriptFunction && ((ScriptFunction)self).data == data && arg instanceof ScriptObject; |
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:
16277
diff
changeset
|
603 |
} |
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:
16277
diff
changeset
|
604 |
|
18868
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
605 |
@SuppressWarnings("unused") |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
606 |
private static Object[] addZerothElement(final Object[] args, final Object value) { |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
607 |
// extends input array with by adding new zeroth element |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
608 |
final Object[] src = (args == null)? ScriptRuntime.EMPTY_ARRAY : args; |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
609 |
final Object[] result = new Object[src.length + 1]; |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
610 |
System.arraycopy(src, 0, result, 1, src.length); |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
611 |
result[0] = value; |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
612 |
return result; |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
613 |
} |
f5359cad148c
8012191: noSuchProperty can't cope with vararg functions
sundar
parents:
18614
diff
changeset
|
614 |
|
16147 | 615 |
private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) { |
616 |
final Class<?> own = ScriptFunction.class; |
|
617 |
final MethodType mt = MH.type(rtype, types); |
|
618 |
try { |
|
619 |
return MH.findStatic(MethodHandles.lookup(), own, name, mt); |
|
620 |
} catch (final MethodHandleFactory.LookupException e) { |
|
621 |
return MH.findVirtual(MethodHandles.lookup(), own, name, mt); |
|
622 |
} |
|
623 |
} |
|
624 |
} |
|
625 |