author | hannesw |
Fri, 19 Sep 2014 13:13:20 +0200 | |
changeset 26764 | c777787a937d |
parent 26510 | a6f3dd80da4c |
child 26768 | 751b0f427090 |
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 |
/* |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
2 |
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. |
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
|
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 |
|
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 |
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
|
27 |
|
17233 | 28 |
import static jdk.nashorn.internal.lookup.Lookup.MH; |
29 |
||
24769 | 30 |
import java.io.IOException; |
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
|
31 |
import java.lang.invoke.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:
diff
changeset
|
32 |
import java.lang.invoke.MethodHandles; |
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
|
33 |
import java.lang.invoke.MethodType; |
24719 | 34 |
import java.util.Collections; |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
35 |
import java.util.HashMap; |
24719 | 36 |
import java.util.HashSet; |
23767 | 37 |
import java.util.Map; |
24719 | 38 |
import java.util.Set; |
25236
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
39 |
import java.util.TreeMap; |
20934
9cbbf2065cd1
8026264: Getter, setter function name mangling issues
sundar
parents:
20559
diff
changeset
|
40 |
import jdk.internal.dynalink.support.NameCodec; |
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.Compiler; |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
42 |
import jdk.nashorn.internal.codegen.Compiler.CompilationPhases; |
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
|
43 |
import jdk.nashorn.internal.codegen.CompilerConstants; |
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
|
44 |
import jdk.nashorn.internal.codegen.FunctionSignature; |
26510
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
45 |
import jdk.nashorn.internal.codegen.ObjectClassGenerator.AllocatorDescriptor; |
25236
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
46 |
import jdk.nashorn.internal.codegen.OptimisticTypesPersistence; |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
47 |
import jdk.nashorn.internal.codegen.TypeMap; |
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:
17233
diff
changeset
|
48 |
import jdk.nashorn.internal.codegen.types.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:
diff
changeset
|
49 |
import jdk.nashorn.internal.ir.FunctionNode; |
24719 | 50 |
import jdk.nashorn.internal.ir.LexicalContext; |
51 |
import jdk.nashorn.internal.ir.visitor.NodeVisitor; |
|
24751 | 52 |
import jdk.nashorn.internal.objects.Global; |
24719 | 53 |
import jdk.nashorn.internal.parser.Parser; |
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
|
54 |
import jdk.nashorn.internal.parser.Token; |
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
|
55 |
import jdk.nashorn.internal.parser.TokenType; |
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
56 |
import jdk.nashorn.internal.runtime.logging.DebugLogger; |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
57 |
import jdk.nashorn.internal.runtime.logging.Loggable; |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
58 |
import jdk.nashorn.internal.runtime.logging.Logger; |
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
|
59 |
/** |
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
|
60 |
* This is a subclass that represents a script function that may be regenerated, |
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
|
61 |
* for example with specialization based on call site types, or lazily generated. |
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
|
62 |
* The common denominator is that it can get new invokers during its lifespan, |
19472
9476460521b3
8023017: SUB missing for widest op == number for BinaryNode
lagergren
parents:
19456
diff
changeset
|
63 |
* unlike {@code FinalScriptFunctionData} |
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
|
64 |
*/ |
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
65 |
@Logger(name="recompile") |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
66 |
public final class RecompilableScriptFunctionData extends ScriptFunctionData implements Loggable { |
24719 | 67 |
/** Prefix used for all recompiled script classes */ |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
68 |
public static final String RECOMPILATION_PREFIX = "Recompilation$"; |
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
|
69 |
|
24719 | 70 |
/** Unique function node id for this function node */ |
71 |
private final int functionNodeId; |
|
72 |
||
73 |
private final String functionName; |
|
74 |
||
24769 | 75 |
/** The line number where this function begins. */ |
24719 | 76 |
private final int lineNumber; |
19456
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
17756
diff
changeset
|
77 |
|
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
17756
diff
changeset
|
78 |
/** Source from which FunctionNode was parsed. */ |
23767 | 79 |
private transient Source source; |
80 |
||
19456
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
17756
diff
changeset
|
81 |
/** Token of this function within the source. */ |
8cc345d620c8
8022524: Memory leaks in nashorn sources and tests found by jhat analysis
sundar
parents:
17756
diff
changeset
|
82 |
private final long token; |
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
83 |
|
26510
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
84 |
/** |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
85 |
* Represents the allocation strategy (property map, script object class, and method handle) for when |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
86 |
* this function is used as a constructor. Note that majority of functions (those not setting any this.* |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
87 |
* properties) will share a single canonical "default strategy" instance. |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
88 |
*/ |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
89 |
private final AllocationStrategy allocationStrategy; |
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
90 |
|
26503 | 91 |
/** |
92 |
* Opaque object representing parser state at the end of the function. Used when reparsing outer function |
|
93 |
* to help with skipping parsing inner functions. |
|
94 |
*/ |
|
95 |
private final Object endParserState; |
|
96 |
||
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
97 |
/** Code installer used for all further recompilation/specialization of this ScriptFunction */ |
23767 | 98 |
private transient CodeInstaller<ScriptEnvironment> installer; |
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
99 |
|
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:
24720
diff
changeset
|
100 |
private final Map<Integer, RecompilableScriptFunctionData> nestedFunctions; |
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:
24720
diff
changeset
|
101 |
|
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:
24720
diff
changeset
|
102 |
/** Id to parent function if one exists */ |
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:
24720
diff
changeset
|
103 |
private RecompilableScriptFunctionData parent; |
24719 | 104 |
|
26503 | 105 |
/** Copy of the {@link FunctionNode} flags. */ |
106 |
private final int functionFlags; |
|
24719 | 107 |
|
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
|
108 |
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); |
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
|
109 |
|
24769 | 110 |
private transient DebugLogger log; |
24731
ab0c8fc915ae
8038406: Testability: as a first step of moving loggers away from the process global space, the Debug object now supports logging POJOs from log entries as an event queue, which can be introspected from test scripts. This is way better than screen scraping brittle and subject-to-change log output.
lagergren
parents:
24729
diff
changeset
|
111 |
|
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:
24720
diff
changeset
|
112 |
private final Map<String, Integer> externalScopeDepths; |
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
113 |
|
24735 | 114 |
private final Set<String> internalSymbols; |
115 |
||
24769 | 116 |
private static final int GET_SET_PREFIX_LENGTH = "*et ".length(); |
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
117 |
|
23767 | 118 |
private static final long serialVersionUID = 4914839316174633726L; |
119 |
||
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
120 |
/** |
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
|
121 |
* Constructor - public as scripts use 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
|
122 |
* |
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:
24720
diff
changeset
|
123 |
* @param functionNode functionNode that represents this function code |
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:
24720
diff
changeset
|
124 |
* @param installer installer for code regeneration versions of this function |
26510
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
125 |
* @param allocationDescriptor descriptor for the allocation behavior when this function is used as a constructor |
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:
24720
diff
changeset
|
126 |
* @param nestedFunctions nested function map |
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:
24720
diff
changeset
|
127 |
* @param externalScopeDepths external scope depths |
24735 | 128 |
* @param internalSymbols internal symbols to method, defined in its scope |
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
|
129 |
*/ |
24719 | 130 |
public RecompilableScriptFunctionData( |
131 |
final FunctionNode functionNode, |
|
132 |
final CodeInstaller<ScriptEnvironment> installer, |
|
26510
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
133 |
final AllocatorDescriptor allocationDescriptor, |
24719 | 134 |
final Map<Integer, RecompilableScriptFunctionData> nestedFunctions, |
24735 | 135 |
final Map<String, Integer> externalScopeDepths, |
136 |
final Set<String> internalSymbols) { |
|
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:
24720
diff
changeset
|
137 |
|
20934
9cbbf2065cd1
8026264: Getter, setter function name mangling issues
sundar
parents:
20559
diff
changeset
|
138 |
super(functionName(functionNode), |
24719 | 139 |
Math.min(functionNode.getParameters().size(), MAX_ARITY), |
26503 | 140 |
getDataFlags(functionNode)); |
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
|
141 |
|
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:
24720
diff
changeset
|
142 |
this.functionName = functionNode.getName(); |
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:
24720
diff
changeset
|
143 |
this.lineNumber = functionNode.getLineNumber(); |
26503 | 144 |
this.functionFlags = functionNode.getFlags() | (functionNode.needsCallee() ? FunctionNode.NEEDS_CALLEE : 0); |
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:
24720
diff
changeset
|
145 |
this.functionNodeId = functionNode.getId(); |
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:
24720
diff
changeset
|
146 |
this.source = functionNode.getSource(); |
26503 | 147 |
this.endParserState = functionNode.getEndParserState(); |
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:
24720
diff
changeset
|
148 |
this.token = tokenFor(functionNode); |
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:
24720
diff
changeset
|
149 |
this.installer = installer; |
26510
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
150 |
this.allocationStrategy = AllocationStrategy.get(allocationDescriptor); |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
151 |
this.nestedFunctions = smallMap(nestedFunctions); |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
152 |
this.externalScopeDepths = smallMap(externalScopeDepths); |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
153 |
this.internalSymbols = smallSet(new HashSet<>(internalSymbols)); |
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:
24720
diff
changeset
|
154 |
|
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:
24720
diff
changeset
|
155 |
for (final RecompilableScriptFunctionData nfn : nestedFunctions.values()) { |
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:
24720
diff
changeset
|
156 |
assert nfn.getParent() == null; |
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:
24720
diff
changeset
|
157 |
nfn.setParent(this); |
23767 | 158 |
} |
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
159 |
|
24769 | 160 |
createLogger(); |
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
161 |
} |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
162 |
|
26510
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
163 |
private static <K, V> Map<K, V> smallMap(final Map<K, V> map) { |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
164 |
if (map == null || map.isEmpty()) { |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
165 |
return Collections.emptyMap(); |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
166 |
} else if (map.size() == 1) { |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
167 |
final Map.Entry<K, V> entry = map.entrySet().iterator().next(); |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
168 |
return Collections.singletonMap(entry.getKey(), entry.getValue()); |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
169 |
} else { |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
170 |
return map; |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
171 |
} |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
172 |
} |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
173 |
|
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
174 |
private static <T> Set<T> smallSet(final Set<T> set) { |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
175 |
if (set == null || set.isEmpty()) { |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
176 |
return Collections.emptySet(); |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
177 |
} else if (set.size() == 1) { |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
178 |
return Collections.singleton(set.iterator().next()); |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
179 |
} else { |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
180 |
return set; |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
181 |
} |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
182 |
} |
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
183 |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
184 |
@Override |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
185 |
public DebugLogger getLogger() { |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
186 |
return log; |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
187 |
} |
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
188 |
|
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
189 |
@Override |
24745
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
190 |
public DebugLogger initLogger(final Context ctxt) { |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
191 |
return ctxt.getLogger(this.getClass()); |
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:
24720
diff
changeset
|
192 |
} |
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:
24720
diff
changeset
|
193 |
|
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:
24720
diff
changeset
|
194 |
/** |
24735 | 195 |
* Check if a symbol is internally defined in a function. For example |
196 |
* if "undefined" is internally defined in the outermost program function, |
|
197 |
* it has not been reassigned or overridden and can be optimized |
|
198 |
* |
|
199 |
* @param symbolName symbol name |
|
200 |
* @return true if symbol is internal to this ScriptFunction |
|
201 |
*/ |
|
202 |
||
203 |
public boolean hasInternalSymbol(final String symbolName) { |
|
204 |
return internalSymbols.contains(symbolName); |
|
205 |
} |
|
206 |
||
207 |
/** |
|
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:
24720
diff
changeset
|
208 |
* Return the external symbol table |
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:
24720
diff
changeset
|
209 |
* @param symbolName symbol name |
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:
24720
diff
changeset
|
210 |
* @return the external symbol table with proto depths |
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:
24720
diff
changeset
|
211 |
*/ |
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:
24720
diff
changeset
|
212 |
public int getExternalSymbolDepth(final String symbolName) { |
26510
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
213 |
final Integer depth = externalScopeDepths.get(symbolName); |
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:
24720
diff
changeset
|
214 |
if (depth == null) { |
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:
24720
diff
changeset
|
215 |
return -1; |
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:
24720
diff
changeset
|
216 |
} |
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:
24720
diff
changeset
|
217 |
return depth; |
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:
24720
diff
changeset
|
218 |
} |
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:
24720
diff
changeset
|
219 |
|
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:
24720
diff
changeset
|
220 |
/** |
26503 | 221 |
* Returns the names of all external symbols this function uses. |
222 |
* @return the names of all external symbols this function uses. |
|
223 |
*/ |
|
224 |
public Set<String> getExternalSymbolNames() { |
|
26510
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
225 |
return Collections.unmodifiableSet(externalScopeDepths.keySet()); |
26503 | 226 |
} |
227 |
||
228 |
/** |
|
229 |
* Returns the opaque object representing the parser state at the end of this function's body, used to |
|
230 |
* skip parsing this function when reparsing its containing outer function. |
|
231 |
* @return the object representing the end parser state |
|
232 |
*/ |
|
233 |
public Object getEndParserState() { |
|
234 |
return endParserState; |
|
235 |
} |
|
236 |
||
237 |
/** |
|
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:
24720
diff
changeset
|
238 |
* Get the parent of this RecompilableScriptFunctionData. If we are |
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:
24720
diff
changeset
|
239 |
* a nested function, we have a parent. Note that "null" return value |
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:
24720
diff
changeset
|
240 |
* can also mean that we have a parent but it is unknown, so this can |
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:
24720
diff
changeset
|
241 |
* only be used for conservative assumptions. |
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:
24720
diff
changeset
|
242 |
* @return parent data, or null if non exists and also null IF UNKNOWN. |
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:
24720
diff
changeset
|
243 |
*/ |
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:
24720
diff
changeset
|
244 |
public RecompilableScriptFunctionData getParent() { |
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:
24720
diff
changeset
|
245 |
return parent; |
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:
24720
diff
changeset
|
246 |
} |
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:
24720
diff
changeset
|
247 |
|
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:
24720
diff
changeset
|
248 |
void setParent(final RecompilableScriptFunctionData parent) { |
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:
24720
diff
changeset
|
249 |
this.parent = parent; |
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
|
250 |
} |
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 |
|
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 |
@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
|
253 |
String toSource() { |
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 |
if (source != null && token != 0) { |
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
|
255 |
return source.getString(Token.descPosition(token), Token.descLength(token)); |
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
|
256 |
} |
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 |
return "function " + (name == null ? "" : name) + "() { [native 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
|
259 |
} |
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
|
260 |
|
24993
b707d46bae40
8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
lagergren
parents:
24778
diff
changeset
|
261 |
/** |
25243
7a1edca6ce94
8048079: Persistent code store is broken after optimistic types merge
hannesw
parents:
25236
diff
changeset
|
262 |
* Initialize transient fields on deserialized instances |
24993
b707d46bae40
8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
lagergren
parents:
24778
diff
changeset
|
263 |
* |
25821
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
25243
diff
changeset
|
264 |
* @param src source |
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
25243
diff
changeset
|
265 |
* @param inst code installer |
24993
b707d46bae40
8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
lagergren
parents:
24778
diff
changeset
|
266 |
*/ |
25821
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
25243
diff
changeset
|
267 |
public void initTransients(final Source src, final CodeInstaller<ScriptEnvironment> inst) { |
25243
7a1edca6ce94
8048079: Persistent code store is broken after optimistic types merge
hannesw
parents:
25236
diff
changeset
|
268 |
if (this.source == null && this.installer == null) { |
25821
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
25243
diff
changeset
|
269 |
this.source = src; |
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
25243
diff
changeset
|
270 |
this.installer = inst; |
fbb51e67d2a7
8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents:
25243
diff
changeset
|
271 |
} else if (this.source != src || this.installer != inst) { |
25243
7a1edca6ce94
8048079: Persistent code store is broken after optimistic types merge
hannesw
parents:
25236
diff
changeset
|
272 |
// Existing values must be same as those passed as parameters |
7a1edca6ce94
8048079: Persistent code store is broken after optimistic types merge
hannesw
parents:
25236
diff
changeset
|
273 |
throw new IllegalArgumentException(); |
23767 | 274 |
} |
275 |
} |
|
276 |
||
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
|
277 |
@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
|
278 |
public String toString() { |
24733
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24731
diff
changeset
|
279 |
return super.toString() + '@' + functionNodeId; |
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24731
diff
changeset
|
280 |
} |
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24731
diff
changeset
|
281 |
|
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24731
diff
changeset
|
282 |
@Override |
1e825be55fd1
8027043: Turn global accesses into MethodHandle.constant, with one chance of reassignment, e.g. x = value occuring once in the global scope is ok, twice is not.
lagergren
parents:
24731
diff
changeset
|
283 |
public String toStringVerbose() { |
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
|
284 |
final StringBuilder sb = new StringBuilder(); |
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
|
285 |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
286 |
sb.append("fnId=").append(functionNodeId).append(' '); |
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:
24720
diff
changeset
|
287 |
|
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
|
288 |
if (source != 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
|
289 |
sb.append(source.getName()) |
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
|
290 |
.append(':') |
24719 | 291 |
.append(lineNumber) |
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 |
.append(' '); |
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
|
293 |
} |
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
|
294 |
|
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
|
295 |
return sb.toString() + super.toString(); |
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
|
296 |
} |
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
|
297 |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
298 |
@Override |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
299 |
public String getFunctionName() { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
300 |
return functionName; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
301 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
302 |
|
24749
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24747
diff
changeset
|
303 |
@Override |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24747
diff
changeset
|
304 |
public boolean inDynamicContext() { |
26503 | 305 |
return getFunctionFlag(FunctionNode.IN_DYNAMIC_CONTEXT); |
24749
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24747
diff
changeset
|
306 |
} |
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24747
diff
changeset
|
307 |
|
20934
9cbbf2065cd1
8026264: Getter, setter function name mangling issues
sundar
parents:
20559
diff
changeset
|
308 |
private static String functionName(final FunctionNode fn) { |
9cbbf2065cd1
8026264: Getter, setter function name mangling issues
sundar
parents:
20559
diff
changeset
|
309 |
if (fn.isAnonymous()) { |
9cbbf2065cd1
8026264: Getter, setter function name mangling issues
sundar
parents:
20559
diff
changeset
|
310 |
return ""; |
9cbbf2065cd1
8026264: Getter, setter function name mangling issues
sundar
parents:
20559
diff
changeset
|
311 |
} |
24719 | 312 |
final FunctionNode.Kind kind = fn.getKind(); |
313 |
if (kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) { |
|
314 |
final String name = NameCodec.decode(fn.getIdent().getName()); |
|
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:
24720
diff
changeset
|
315 |
return name.substring(GET_SET_PREFIX_LENGTH); |
24719 | 316 |
} |
317 |
return fn.getIdent().getName(); |
|
20934
9cbbf2065cd1
8026264: Getter, setter function name mangling issues
sundar
parents:
20559
diff
changeset
|
318 |
} |
9cbbf2065cd1
8026264: Getter, setter function name mangling issues
sundar
parents:
20559
diff
changeset
|
319 |
|
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
|
320 |
private static long tokenFor(final FunctionNode fn) { |
24719 | 321 |
final int position = Token.descPosition(fn.getFirstToken()); |
24994
92a19723a5ac
8047035: (function() "hello")() crashes in Lexer with jdk9
sundar
parents:
24993
diff
changeset
|
322 |
final long lastToken = Token.withDelimiter(fn.getLastToken()); |
24719 | 323 |
// EOL uses length field to store the line number |
324 |
final int length = Token.descPosition(lastToken) - position + (Token.descType(lastToken) == TokenType.EOL ? 0 : Token.descLength(lastToken)); |
|
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
|
325 |
|
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
|
326 |
return Token.toDesc(TokenType.FUNCTION, position, length); |
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
|
327 |
} |
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
|
328 |
|
26503 | 329 |
private static int getDataFlags(final FunctionNode functionNode) { |
23372
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
330 |
int flags = IS_CONSTRUCTOR; |
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
331 |
if (functionNode.isStrict()) { |
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
332 |
flags |= IS_STRICT; |
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
333 |
} |
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
334 |
if (functionNode.needsCallee()) { |
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
335 |
flags |= NEEDS_CALLEE; |
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
336 |
} |
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
337 |
if (functionNode.usesThis() || functionNode.hasEval()) { |
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
338 |
flags |= USES_THIS; |
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
339 |
} |
24727 | 340 |
if (functionNode.isVarArg()) { |
341 |
flags |= IS_VARIABLE_ARITY; |
|
342 |
} |
|
23372
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
343 |
return flags; |
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
344 |
} |
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
345 |
|
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
|
346 |
@Override |
24727 | 347 |
PropertyMap getAllocatorMap() { |
26510
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
348 |
return allocationStrategy.getAllocatorMap(); |
24727 | 349 |
} |
350 |
||
351 |
@Override |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
20946
diff
changeset
|
352 |
ScriptObject allocate(final PropertyMap map) { |
26510
a6f3dd80da4c
8058100: Reduce the RecompilableScriptFunctionData footprint
attila
parents:
26503
diff
changeset
|
353 |
return allocationStrategy.allocate(map); |
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
|
354 |
} |
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
|
355 |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
356 |
FunctionNode reparse() { |
24719 | 357 |
// NOTE: If we aren't recompiling the top-level program, we decrease functionNodeId 'cause we'll have a synthetic program node |
358 |
final int descPosition = Token.descPosition(token); |
|
24769 | 359 |
final Context context = Context.getContextTrusted(); |
24719 | 360 |
final Parser parser = new Parser( |
24745
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
361 |
context.getEnv(), |
24719 | 362 |
source, |
363 |
new Context.ThrowErrorManager(), |
|
364 |
isStrict(), |
|
24745
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
365 |
lineNumber - 1, |
3a6e1477362b
8041434: Add synchronization to the common global constants structure
lagergren
parents:
24744
diff
changeset
|
366 |
context.getLogger(Parser.class)); // source starts at line 0, so even though lineNumber is the correct declaration line, back off one to make it exclusive |
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
|
367 |
|
26503 | 368 |
if (getFunctionFlag(FunctionNode.IS_ANONYMOUS)) { |
24719 | 369 |
parser.setFunctionName(functionName); |
370 |
} |
|
26503 | 371 |
parser.setReparsedFunction(this); |
24749
1549c85f8200
8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents:
24747
diff
changeset
|
372 |
|
26503 | 373 |
final FunctionNode program = parser.parse(CompilerConstants.PROGRAM.symbolName(), descPosition, |
374 |
Token.descLength(token), true); |
|
375 |
// Parser generates a program AST even if we're recompiling a single function, so when we are only |
|
376 |
// recompiling a single function, extract it from the program. |
|
377 |
return (isProgram() ? program : extractFunctionFromScript(program)).setName(null, functionName); |
|
378 |
} |
|
379 |
||
380 |
private boolean getFunctionFlag(final int flag) { |
|
381 |
return (functionFlags & flag) != 0; |
|
382 |
} |
|
383 |
||
384 |
private boolean isProgram() { |
|
385 |
return getFunctionFlag(FunctionNode.IS_PROGRAM); |
|
24719 | 386 |
} |
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
|
387 |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
388 |
TypeMap typeMap(final MethodType fnCallSiteType) { |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
389 |
if (fnCallSiteType == null) { |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
390 |
return null; |
24719 | 391 |
} |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
392 |
|
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
393 |
if (CompiledFunction.isVarArgsType(fnCallSiteType)) { |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
394 |
return null; |
24719 | 395 |
} |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
396 |
|
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
397 |
return new TypeMap(functionNodeId, explicitParams(fnCallSiteType), needsCallee()); |
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:
17233
diff
changeset
|
398 |
} |
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:
17233
diff
changeset
|
399 |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
400 |
private static ScriptObject newLocals(final ScriptObject runtimeScope) { |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
401 |
final ScriptObject locals = Global.newEmptyInstance(); |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
402 |
locals.setProto(runtimeScope); |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
403 |
return locals; |
24740
26791be09688
8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents:
24738
diff
changeset
|
404 |
} |
26791be09688
8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents:
24738
diff
changeset
|
405 |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
406 |
private Compiler getCompiler(final FunctionNode fn, final MethodType actualCallSiteType, final ScriptObject runtimeScope) { |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
407 |
return getCompiler(fn, actualCallSiteType, newLocals(runtimeScope), null, null); |
24740
26791be09688
8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents:
24738
diff
changeset
|
408 |
} |
26791be09688
8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents:
24738
diff
changeset
|
409 |
|
25236
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
410 |
Compiler getCompiler(final FunctionNode functionNode, final MethodType actualCallSiteType, |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
411 |
final ScriptObject runtimeScope, final Map<Integer, Type> invalidatedProgramPoints, |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
412 |
final int[] continuationEntryPoints) { |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
413 |
final TypeMap typeMap = typeMap(actualCallSiteType); |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
414 |
final Type[] paramTypes = typeMap == null ? null : typeMap.getParameterTypes(functionNodeId); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
415 |
final Object typeInformationFile = OptimisticTypesPersistence.getLocationDescriptor(source, functionNodeId, paramTypes); |
24769 | 416 |
final Context context = Context.getContextTrusted(); |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
417 |
return new Compiler( |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
418 |
context, |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
419 |
context.getEnv(), |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
420 |
installer, |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
421 |
functionNode.getSource(), // source |
26377
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
26068
diff
changeset
|
422 |
context.getErrorManager(), |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
423 |
isStrict() | functionNode.isStrict(), // is strict |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
424 |
true, // is on demand |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
425 |
this, // compiledFunction, i.e. this RecompilableScriptFunctionData |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
426 |
typeMap, // type map |
25236
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
427 |
getEffectiveInvalidatedProgramPoints(invalidatedProgramPoints, typeInformationFile), // invalidated program points |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
428 |
typeInformationFile, |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
429 |
continuationEntryPoints, // continuation entry points |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
430 |
runtimeScope); // runtime scope |
24751 | 431 |
} |
432 |
||
25236
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
433 |
/** |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
434 |
* If the function being compiled already has its own invalidated program points map, use it. Otherwise, attempt to |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
435 |
* load invalidated program points map from the persistent type info cache. |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
436 |
* @param invalidatedProgramPoints the function's current invalidated program points map. Null if the function |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
437 |
* doesn't have it. |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
438 |
* @param typeInformationFile the object describing the location of the persisted type information. |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
439 |
* @return either the existing map, or a loaded map from the persistent type info cache, or a new empty map if |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
440 |
* neither an existing map or a persistent cached type info is available. |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
441 |
*/ |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
442 |
private static Map<Integer, Type> getEffectiveInvalidatedProgramPoints( |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
443 |
final Map<Integer, Type> invalidatedProgramPoints, final Object typeInformationFile) { |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
444 |
if(invalidatedProgramPoints != null) { |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
445 |
return invalidatedProgramPoints; |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
446 |
} |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
447 |
final Map<Integer, Type> loadedProgramPoints = OptimisticTypesPersistence.load(typeInformationFile); |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
448 |
return loadedProgramPoints != null ? loadedProgramPoints : new TreeMap<Integer, Type>(); |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
449 |
} |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
450 |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
451 |
private FunctionInitializer compileTypeSpecialization(final MethodType actualCallSiteType, final ScriptObject runtimeScope, final boolean persist) { |
24751 | 452 |
// We're creating an empty script object for holding local variables. AssignSymbols will populate it with |
453 |
// explicit Undefined values for undefined local variables (see AssignSymbols#defineSymbol() and |
|
454 |
// CompilationEnvironment#declareLocalSymbol()). |
|
24731
ab0c8fc915ae
8038406: Testability: as a first step of moving loggers away from the process global space, the Debug object now supports logging POJOs from log entries as an event queue, which can be introspected from test scripts. This is way better than screen scraping brittle and subject-to-change log output.
lagergren
parents:
24729
diff
changeset
|
455 |
|
24744
5290da85fc3d
8038426: Move all loggers from process wide scope into Global scope
lagergren
parents:
24740
diff
changeset
|
456 |
if (log.isEnabled()) { |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
457 |
log.info("Type specialization of '", functionName, "' signature: ", actualCallSiteType); |
24731
ab0c8fc915ae
8038406: Testability: as a first step of moving loggers away from the process global space, the Debug object now supports logging POJOs from log entries as an event queue, which can be introspected from test scripts. This is way better than screen scraping brittle and subject-to-change log output.
lagergren
parents:
24729
diff
changeset
|
458 |
} |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
459 |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
460 |
final boolean persistentCache = usePersistentCodeCache() && persist; |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
461 |
String cacheKey = null; |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
462 |
if (persistentCache) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
463 |
final TypeMap typeMap = typeMap(actualCallSiteType); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
464 |
final Type[] paramTypes = typeMap == null ? null : typeMap.getParameterTypes(functionNodeId); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
465 |
cacheKey = CodeStore.getCacheKey(functionNodeId, paramTypes); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
466 |
final StoredScript script = installer.loadScript(source, cacheKey); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
467 |
|
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
468 |
if (script != null) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
469 |
Compiler.updateCompilationId(script.getCompilationId()); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
470 |
return install(script); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
471 |
} |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
472 |
} |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
473 |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
474 |
final FunctionNode fn = reparse(); |
25236
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
475 |
final Compiler compiler = getCompiler(fn, actualCallSiteType, runtimeScope); |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
476 |
final FunctionNode compiledFn = compiler.compile(fn, CompilationPhases.COMPILE_ALL); |
25236
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
477 |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
478 |
if (persist && !compiledFn.getFlag(FunctionNode.HAS_APPLY_TO_CALL_SPECIALIZATION)) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
479 |
compiler.persistClassInfo(cacheKey, compiledFn); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
480 |
} |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
481 |
return new FunctionInitializer(compiledFn, compiler.getInvalidatedProgramPoints()); |
25236
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
482 |
} |
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
483 |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
484 |
|
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
485 |
/** |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
486 |
* Install this script using the given {@code installer}. |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
487 |
* |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
488 |
* @param script the compiled script |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
489 |
* @return the function initializer |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
490 |
*/ |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
491 |
private FunctionInitializer install(final StoredScript script) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
492 |
|
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
493 |
final Map<String, Class<?>> installedClasses = new HashMap<>(); |
26764
c777787a937d
8046202: Make persistent code store more flexible
hannesw
parents:
26510
diff
changeset
|
494 |
final Map<String, byte[]> classBytes = script.getClassBytes(); |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
495 |
final String mainClassName = script.getMainClassName(); |
26764
c777787a937d
8046202: Make persistent code store more flexible
hannesw
parents:
26510
diff
changeset
|
496 |
final byte[] mainClassBytes = classBytes.get(mainClassName); |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
497 |
|
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
498 |
final Class<?> mainClass = installer.install(mainClassName, mainClassBytes); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
499 |
|
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
500 |
installedClasses.put(mainClassName, mainClass); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
501 |
|
26764
c777787a937d
8046202: Make persistent code store more flexible
hannesw
parents:
26510
diff
changeset
|
502 |
for (final Map.Entry<String, byte[]> entry : classBytes.entrySet()) { |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
503 |
final String className = entry.getKey(); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
504 |
final byte[] code = entry.getValue(); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
505 |
|
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
506 |
if (className.equals(mainClassName)) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
507 |
continue; |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
508 |
} |
25236
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
509 |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
510 |
installedClasses.put(className, installer.install(className, code)); |
25236
fac419f1e889
8046921: Deoptimization type information peristence
attila
parents:
24994
diff
changeset
|
511 |
} |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
512 |
|
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
513 |
final Map<Integer, FunctionInitializer> initializers = script.getInitializers(); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
514 |
assert initializers != null; |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
515 |
assert initializers.size() == 1; |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
516 |
final FunctionInitializer initializer = initializers.values().iterator().next(); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
517 |
|
26067
b32ccc3a76c9
8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents:
26055
diff
changeset
|
518 |
final Object[] constants = script.getConstants(); |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
519 |
for (int i = 0; i < constants.length; i++) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
520 |
if (constants[i] instanceof RecompilableScriptFunctionData) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
521 |
// replace deserialized function data with the ones we already have |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
522 |
constants[i] = getScriptFunctionData(((RecompilableScriptFunctionData) constants[i]).getFunctionNodeId()); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
523 |
} |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
524 |
} |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
525 |
|
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
526 |
installer.initialize(installedClasses.values(), source, constants); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
527 |
initializer.setCode(installedClasses.get(initializer.getClassName())); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
528 |
return initializer; |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
529 |
} |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
530 |
|
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
531 |
boolean usePersistentCodeCache() { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
532 |
final ScriptEnvironment env = installer.getOwner(); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
533 |
return env._persistent_cache && env._optimistic_types; |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
20946
diff
changeset
|
534 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
20946
diff
changeset
|
535 |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
536 |
private MethodType explicitParams(final MethodType callSiteType) { |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
537 |
if (CompiledFunction.isVarArgsType(callSiteType)) { |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
538 |
return null; |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
539 |
} |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
540 |
|
24719 | 541 |
final MethodType noCalleeThisType = callSiteType.dropParameterTypes(0, 2); // (callee, this) is always in call site type |
542 |
final int callSiteParamCount = noCalleeThisType.parameterCount(); |
|
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
543 |
|
24719 | 544 |
// Widen parameters of reference types to Object as we currently don't care for specialization among reference |
545 |
// types. E.g. call site saying (ScriptFunction, Object, String) should still link to (ScriptFunction, Object, Object) |
|
546 |
final Class<?>[] paramTypes = noCalleeThisType.parameterArray(); |
|
547 |
boolean changed = false; |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
548 |
for (int i = 0; i < paramTypes.length; ++i) { |
24719 | 549 |
final Class<?> paramType = paramTypes[i]; |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
550 |
if (!(paramType.isPrimitive() || paramType == Object.class)) { |
24719 | 551 |
paramTypes[i] = Object.class; |
552 |
changed = true; |
|
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:
17233
diff
changeset
|
553 |
} |
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:
17233
diff
changeset
|
554 |
} |
24719 | 555 |
final MethodType generalized = changed ? MethodType.methodType(noCalleeThisType.returnType(), paramTypes) : noCalleeThisType; |
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:
17233
diff
changeset
|
556 |
|
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
557 |
if (callSiteParamCount < getArity()) { |
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
558 |
return generalized.appendParameterTypes(Collections.<Class<?>>nCopies(getArity() - callSiteParamCount, Object.class)); |
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
559 |
} |
24759
31aed7d9c02a
8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents:
24751
diff
changeset
|
560 |
return generalized; |
24719 | 561 |
} |
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
562 |
|
24719 | 563 |
private FunctionNode extractFunctionFromScript(final FunctionNode script) { |
564 |
final Set<FunctionNode> fns = new HashSet<>(); |
|
565 |
script.getBody().accept(new NodeVisitor<LexicalContext>(new LexicalContext()) { |
|
566 |
@Override |
|
567 |
public boolean enterFunctionNode(final FunctionNode fn) { |
|
568 |
fns.add(fn); |
|
569 |
return false; |
|
570 |
} |
|
571 |
}); |
|
572 |
assert fns.size() == 1 : "got back more than one method in recompilation"; |
|
573 |
final FunctionNode f = fns.iterator().next(); |
|
574 |
assert f.getId() == functionNodeId; |
|
26503 | 575 |
if (!getFunctionFlag(FunctionNode.IS_DECLARED) && f.isDeclared()) { |
24719 | 576 |
return f.clearFlag(null, FunctionNode.IS_DECLARED); |
577 |
} |
|
578 |
return f; |
|
579 |
} |
|
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:
17233
diff
changeset
|
580 |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
581 |
MethodHandle lookup(final FunctionInitializer fnInit) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
582 |
final MethodType type = fnInit.getMethodType(); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
583 |
return lookupCodeMethod(fnInit.getCode(), type); |
24719 | 584 |
} |
585 |
||
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
586 |
MethodHandle lookup(final FunctionNode fn) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
587 |
final MethodType type = new FunctionSignature(fn).getMethodType(); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
588 |
return lookupCodeMethod(fn.getCompileUnit().getCode(), 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:
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:
diff
changeset
|
590 |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
591 |
MethodHandle lookupCodeMethod(final Class<?> code, final MethodType targetType) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
592 |
log.info("Looking up ", DebugLogger.quote(name), " type=", targetType); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
593 |
return MH.findStatic(LOOKUP, code, functionName, targetType); |
24719 | 594 |
} |
595 |
||
596 |
/** |
|
597 |
* Initializes this function data with the eagerly generated version of the code. This method can only be invoked |
|
598 |
* by the compiler internals in Nashorn and is public for implementation reasons only. Attempting to invoke it |
|
599 |
* externally will result in an exception. |
|
600 |
*/ |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
601 |
public void initializeCode(final FunctionInitializer initializer) { |
24719 | 602 |
// Since the method is public, we double-check that we aren't invoked with an inappropriate compile unit. |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
603 |
if(!code.isEmpty()) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
604 |
throw new IllegalStateException(name); |
24719 | 605 |
} |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
606 |
addCode(lookup(initializer), null, null, initializer.getFlags()); |
24719 | 607 |
} |
608 |
||
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
609 |
private CompiledFunction addCode(final MethodHandle target, final Map<Integer, Type> invalidatedProgramPoints, |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
610 |
final MethodType callSiteType, final int fnFlags) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
611 |
final CompiledFunction cfn = new CompiledFunction(target, this, invalidatedProgramPoints, callSiteType, fnFlags); |
24719 | 612 |
code.add(cfn); |
613 |
return cfn; |
|
614 |
} |
|
615 |
||
616 |
/** |
|
617 |
* Add code with specific call site type. It will adapt the type of the looked up method handle to fit the call site |
|
618 |
* type. This is necessary because even if we request a specialization that takes an "int" parameter, we might end |
|
619 |
* up getting one that takes a "double" etc. because of internal function logic causes widening (e.g. assignment of |
|
620 |
* a wider value to the parameter variable). However, we use the method handle type for matching subsequent lookups |
|
621 |
* for the same specialization, so we must adapt the handle to the expected type. |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
622 |
* @param fnInit the function |
24719 | 623 |
* @param callSiteType the call site type |
624 |
* @return the compiled function object, with its type matching that of the call site type. |
|
625 |
*/ |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
626 |
private CompiledFunction addCode(final FunctionInitializer fnInit, final MethodType callSiteType) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
627 |
if (isVariableArity()) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
628 |
return addCode(lookup(fnInit), fnInit.getInvalidatedProgramPoints(), callSiteType, fnInit.getFlags()); |
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:
17233
diff
changeset
|
629 |
} |
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:
17233
diff
changeset
|
630 |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
631 |
final MethodHandle handle = lookup(fnInit); |
24719 | 632 |
final MethodType fromType = handle.type(); |
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:
24720
diff
changeset
|
633 |
MethodType toType = needsCallee(fromType) ? callSiteType.changeParameterType(0, ScriptFunction.class) : callSiteType.dropParameterTypes(0, 1); |
24719 | 634 |
toType = toType.changeReturnType(fromType.returnType()); |
635 |
||
636 |
final int toCount = toType.parameterCount(); |
|
637 |
final int fromCount = fromType.parameterCount(); |
|
638 |
final int minCount = Math.min(fromCount, toCount); |
|
639 |
for(int i = 0; i < minCount; ++i) { |
|
640 |
final Class<?> fromParam = fromType.parameterType(i); |
|
641 |
final Class<?> toParam = toType.parameterType(i); |
|
642 |
// If method has an Object parameter, but call site had String, preserve it as Object. No need to narrow it |
|
643 |
// artificially. Note that this is related to how CompiledFunction.matchesCallSite() works, specifically |
|
644 |
// the fact that various reference types compare to equal (see "fnType.isEquivalentTo(csType)" there). |
|
24740
26791be09688
8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents:
24738
diff
changeset
|
645 |
if (fromParam != toParam && !fromParam.isPrimitive() && !toParam.isPrimitive()) { |
24719 | 646 |
assert fromParam.isAssignableFrom(toParam); |
647 |
toType = toType.changeParameterType(i, fromParam); |
|
648 |
} |
|
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:
17233
diff
changeset
|
649 |
} |
24740
26791be09688
8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents:
24738
diff
changeset
|
650 |
if (fromCount > toCount) { |
24719 | 651 |
toType = toType.appendParameterTypes(fromType.parameterList().subList(toCount, fromCount)); |
24740
26791be09688
8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents:
24738
diff
changeset
|
652 |
} else if (fromCount < toCount) { |
24719 | 653 |
toType = toType.dropParameterTypes(fromCount, toCount); |
654 |
} |
|
655 |
||
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
656 |
return addCode(lookup(fnInit).asType(toType), fnInit.getInvalidatedProgramPoints(), callSiteType, fnInit.getFlags()); |
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
20946
diff
changeset
|
657 |
} |
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
20946
diff
changeset
|
658 |
|
23372
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
659 |
|
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
660 |
@Override |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
661 |
synchronized CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
662 |
CompiledFunction existingBest = super.getBest(callSiteType, runtimeScope); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
663 |
if (existingBest == null) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
664 |
existingBest = addCode(compileTypeSpecialization(callSiteType, runtimeScope, true), callSiteType); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
665 |
} |
24740
26791be09688
8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents:
24738
diff
changeset
|
666 |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
667 |
assert existingBest != null; |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
668 |
//we are calling a vararg method with real args |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
669 |
boolean applyToCall = existingBest.isVarArg() && !CompiledFunction.isVarArgsType(callSiteType); |
23767 | 670 |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
671 |
//if the best one is an apply to call, it has to match the callsite exactly |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
672 |
//or we need to regenerate |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
673 |
if (existingBest.isApplyToCall()) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
674 |
final CompiledFunction best = lookupExactApplyToCall(callSiteType); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
675 |
if (best != null) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
676 |
return best; |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
677 |
} |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
678 |
applyToCall = true; |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
679 |
} |
24740
26791be09688
8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents:
24738
diff
changeset
|
680 |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
681 |
if (applyToCall) { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
682 |
final FunctionInitializer fnInit = compileTypeSpecialization(callSiteType, runtimeScope, false); |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
683 |
if ((fnInit.getFlags() & FunctionNode.HAS_APPLY_TO_CALL_SPECIALIZATION) != 0) { //did the specialization work |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
684 |
existingBest = addCode(fnInit, callSiteType); |
24740
26791be09688
8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents:
24738
diff
changeset
|
685 |
} |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
686 |
} |
24740
26791be09688
8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents:
24738
diff
changeset
|
687 |
|
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
688 |
return existingBest; |
23372
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
689 |
} |
09707b3e5fb0
8021350: Share script classes between threads/globals within context
hannesw
parents:
23084
diff
changeset
|
690 |
|
23084
6c5c02d1023a
8035948: Redesign property listeners for shared classes
hannesw
parents:
20946
diff
changeset
|
691 |
@Override |
24719 | 692 |
boolean isRecompilable() { |
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
693 |
return true; |
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
694 |
} |
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
695 |
|
24719 | 696 |
@Override |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
697 |
public boolean needsCallee() { |
26503 | 698 |
return getFunctionFlag(FunctionNode.NEEDS_CALLEE); |
699 |
} |
|
700 |
||
701 |
/** |
|
702 |
* Returns the {@link FunctionNode} flags associated with this function data. |
|
703 |
* @return the {@link FunctionNode} flags associated with this function data. |
|
704 |
*/ |
|
705 |
public int getFunctionFlags() { |
|
706 |
return functionFlags; |
|
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
707 |
} |
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:
17233
diff
changeset
|
708 |
|
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
|
709 |
@Override |
24719 | 710 |
MethodType getGenericType() { |
711 |
// 2 is for (callee, this) |
|
712 |
if (isVariableArity()) { |
|
713 |
return MethodType.genericMethodType(2, true); |
|
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
714 |
} |
24719 | 715 |
return MethodType.genericMethodType(2 + getArity()); |
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
716 |
} |
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
717 |
|
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
718 |
/** |
26055
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
719 |
* Return the function node id. |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
720 |
* @return the function node id |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
721 |
*/ |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
722 |
public int getFunctionNodeId() { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
723 |
return functionNodeId; |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
724 |
} |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
725 |
|
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
726 |
public Source getSource() { |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
727 |
return source; |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
728 |
} |
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
729 |
|
fe8be844ba50
8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents:
25821
diff
changeset
|
730 |
/** |
24719 | 731 |
* Return a script function data based on a function id, either this function if |
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:
24720
diff
changeset
|
732 |
* the id matches or a nested function based on functionId. This goes down into |
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:
24720
diff
changeset
|
733 |
* nested functions until all leaves are exhausted. |
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:
24720
diff
changeset
|
734 |
* |
24719 | 735 |
* @param functionId function id |
736 |
* @return script function data or null if invalid id |
|
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
737 |
*/ |
24719 | 738 |
public RecompilableScriptFunctionData getScriptFunctionData(final int functionId) { |
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:
24720
diff
changeset
|
739 |
if (functionId == functionNodeId) { |
24719 | 740 |
return this; |
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
741 |
} |
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:
24720
diff
changeset
|
742 |
RecompilableScriptFunctionData data; |
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:
17233
diff
changeset
|
743 |
|
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:
24720
diff
changeset
|
744 |
data = nestedFunctions == null ? null : nestedFunctions.get(functionId); |
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:
24720
diff
changeset
|
745 |
if (data != null) { |
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:
24720
diff
changeset
|
746 |
return data; |
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
747 |
} |
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:
24720
diff
changeset
|
748 |
for (final RecompilableScriptFunctionData ndata : nestedFunctions.values()) { |
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:
24720
diff
changeset
|
749 |
data = ndata.getScriptFunctionData(functionId); |
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:
24720
diff
changeset
|
750 |
if (data != null) { |
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:
24720
diff
changeset
|
751 |
return data; |
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:
17233
diff
changeset
|
752 |
} |
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
753 |
} |
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:
24720
diff
changeset
|
754 |
return null; |
17756
daaa1e643f71
8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
17523
diff
changeset
|
755 |
} |
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:
17233
diff
changeset
|
756 |
|
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
757 |
/** |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
758 |
* Check whether a certain name is a global symbol, i.e. only exists as defined |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
759 |
* in outermost scope and not shadowed by being parameter or assignment in inner |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
760 |
* scopes |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
761 |
* |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
762 |
* @param functionNode function node to check |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
763 |
* @param symbolName symbol name |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
764 |
* @return true if global symbol |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
765 |
*/ |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
766 |
public boolean isGlobalSymbol(final FunctionNode functionNode, final String symbolName) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
767 |
RecompilableScriptFunctionData data = getScriptFunctionData(functionNode.getId()); |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
768 |
assert data != null; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
769 |
|
24751 | 770 |
do { |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
771 |
if (data.hasInternalSymbol(symbolName)) { |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
772 |
return false; |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
773 |
} |
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
774 |
data = data.getParent(); |
24751 | 775 |
} while(data != null); |
24738
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
776 |
|
be2026c9717c
8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents:
24735
diff
changeset
|
777 |
return 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
|
778 |
} |
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
|
779 |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
24769
diff
changeset
|
780 |
private void readObject(final java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { |
24769 | 781 |
in.defaultReadObject(); |
782 |
createLogger(); |
|
783 |
} |
|
784 |
||
785 |
private void createLogger() { |
|
786 |
log = initLogger(Context.getContextTrusted()); |
|
787 |
} |
|
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
|
788 |
} |