nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Compiler.java
author sundar
Mon, 14 Sep 2015 16:13:10 +0530
changeset 32692 8f60bd284bf4
parent 32530 20aa15248117
child 33533 43400f0f2b47
permissions -rw-r--r--
8055917: jdk.nashorn.internal.codegen.CompilationPhase$N should be renamed to proper classes Reviewed-by: attila, hannesw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     1
/*
16151
97c1e756ae1e 8005663: Update copyright year to 2013
jlaskey
parents: 16147
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     4
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    10
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    15
 * accompanied this code).
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    16
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    20
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    23
 * questions.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    24
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    25
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    26
package jdk.nashorn.internal.codegen;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    28
import static jdk.nashorn.internal.codegen.CompilerConstants.ARGUMENTS;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    29
import static jdk.nashorn.internal.codegen.CompilerConstants.CALLEE;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    30
import static jdk.nashorn.internal.codegen.CompilerConstants.RETURN;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    31
import static jdk.nashorn.internal.codegen.CompilerConstants.SCOPE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    32
import static jdk.nashorn.internal.codegen.CompilerConstants.THIS;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    33
import static jdk.nashorn.internal.codegen.CompilerConstants.VARARGS;
24764
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
    34
import static jdk.nashorn.internal.runtime.logging.DebugLogger.quote;
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
    35
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    36
import java.io.File;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    37
import java.lang.invoke.MethodType;
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
    38
import java.util.ArrayList;
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
    39
import java.util.Arrays;
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
    40
import java.util.Collections;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
    41
import java.util.Comparator;
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
    42
import java.util.HashMap;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    43
import java.util.Iterator;
20928
3ff39d5c8c08 8026137: Fix Issues with Binary Evaluation Order
lagergren
parents: 18865
diff changeset
    44
import java.util.LinkedHashMap;
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
    45
import java.util.List;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    46
import java.util.Map;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    47
import java.util.Set;
25236
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
    48
import java.util.TreeMap;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    49
import java.util.concurrent.atomic.AtomicInteger;
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: 24779
diff changeset
    50
import java.util.function.Consumer;
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: 16275
diff changeset
    51
import java.util.logging.Level;
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents: 16233
diff changeset
    52
import jdk.internal.dynalink.support.NameCodec;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    53
import jdk.nashorn.internal.codegen.types.Type;
26507
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
    54
import jdk.nashorn.internal.ir.Expression;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    55
import jdk.nashorn.internal.ir.FunctionNode;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    56
import jdk.nashorn.internal.ir.Optimistic;
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
    57
import jdk.nashorn.internal.ir.debug.ClassHistogramElement;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
    58
import jdk.nashorn.internal.ir.debug.ObjectSizeCalculator;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    59
import jdk.nashorn.internal.runtime.CodeInstaller;
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
    60
import jdk.nashorn.internal.runtime.Context;
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
    61
import jdk.nashorn.internal.runtime.ErrorManager;
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
    62
import jdk.nashorn.internal.runtime.FunctionInitializer;
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
    63
import jdk.nashorn.internal.runtime.ParserException;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
    64
import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
16262
75513555e603 8008731: Separate configuration environment (options, error/output writer etc.) from Context
sundar
parents: 16252
diff changeset
    65
import jdk.nashorn.internal.runtime.ScriptEnvironment;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    66
import jdk.nashorn.internal.runtime.ScriptObject;
26507
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
    67
import jdk.nashorn.internal.runtime.ScriptRuntime;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    68
import jdk.nashorn.internal.runtime.Source;
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
    69
import jdk.nashorn.internal.runtime.logging.DebugLogger;
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
    70
import jdk.nashorn.internal.runtime.logging.Loggable;
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
    71
import jdk.nashorn.internal.runtime.logging.Logger;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    72
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    73
/**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    74
 * Responsible for converting JavaScripts to java byte code. Main entry
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
    75
 * point for code generator. The compiler may also install classes given some
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
    76
 * predefined Code installation policy, given to it at construction time.
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
    77
 * @see CodeInstaller
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    78
 */
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
    79
@Logger(name="compiler")
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
    80
public final class Compiler implements Loggable {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    81
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    82
    /** Name of the scripts package */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    83
    public static final String SCRIPTS_PACKAGE = "jdk/nashorn/internal/scripts";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    84
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    85
    /** Name of the objects package */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    86
    public static final String OBJECTS_PACKAGE = "jdk/nashorn/internal/objects";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    87
24764
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
    88
    private final ScriptEnvironment env;
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
    89
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    90
    private final Source source;
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
    91
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    92
    private final String sourceName;
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
    93
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
    94
    private final ErrorManager errors;
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
    95
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    96
    private final boolean optimistic;
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 20928
diff changeset
    97
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
    98
    private final Map<String, byte[]> bytecode;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    99
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   100
    private final Set<CompileUnit> compileUnits;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   101
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   102
    private final ConstantData constantData;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   103
32530
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   104
    private final CodeInstaller installer;
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   105
31195
4ff0587b9ed1 8098807: Strict eval throws ClassCastException with large scripts
hannesw
parents: 30056
diff changeset
   106
    /** logger for compiler, trampolines and related code generation events
16252
3bfe9b68a0fa 8008648: Lazy JIT scope and callee semantics bugfixes. Broke out wallclock timer.
lagergren
parents: 16250
diff changeset
   107
     *  that affect classes */
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   108
    private final 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: 24722
diff changeset
   109
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   110
    private final Context context;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   111
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   112
    private final TypeMap types;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   113
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   114
    // Runtime scope in effect at the time of the compilation. Used to evaluate types of expressions and prevent overly
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   115
    // optimistic assumptions (which will lead to unnecessary deoptimizing recompilations).
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   116
    private final TypeEvaluator typeEvaluator;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   117
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   118
    private final boolean strict;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   119
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   120
    private final boolean onDemand;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   121
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   122
    /**
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   123
     * If this is a recompilation, this is how we pass in the invalidations, e.g. programPoint=17, Type == int means
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   124
     * that using whatever was at program point 17 as an int failed.
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   125
     */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   126
    private final Map<Integer, Type> invalidatedProgramPoints;
25241
92eb440faf5c 8048009: Type info caching accidentally defeated
attila
parents: 25236
diff changeset
   127
25236
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   128
    /**
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   129
     * Descriptor of the location where we write the type information after compilation.
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   130
     */
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   131
    private final Object typeInformationFile;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   132
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   133
    /**
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   134
     * Compile unit name of first compile unit - this prefix will be used for all
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   135
     * classes that a compilation generates.
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   136
     */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   137
    private final String firstCompileUnitName;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   138
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   139
    /**
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   140
     * Contains the program point that should be used as the continuation entry point, as well as all previous
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   141
     * continuation entry points executed as part of a single logical invocation of the function. In practical terms, if
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   142
     * we execute a rest-of method from the program point 17, but then we hit deoptimization again during it at program
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   143
     * point 42, and execute a rest-of method from the program point 42, and then we hit deoptimization again at program
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   144
     * point 57 and are compiling a rest-of method for it, the values in the array will be [57, 42, 17]. This is only
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   145
     * set when compiling a rest-of method. If this method is a rest-of for a non-rest-of method, the array will have
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   146
     * one element. If it is a rest-of for a rest-of, the array will have two elements, and so on.
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   147
     */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   148
    private final int[] continuationEntryPoints;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   149
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   150
    /**
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   151
     * ScriptFunction data for what is being compile, where applicable.
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   152
     * TODO: make this immutable, propagate it through the CompilationPhases
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   153
     */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   154
    private RecompilableScriptFunctionData compiledFunction;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   155
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   156
    /**
26887
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26510
diff changeset
   157
     * Most compile unit names are longer than the default StringBuilder buffer,
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26510
diff changeset
   158
     * worth startup performance when massive class generation is going on to increase
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26510
diff changeset
   159
     * this
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26510
diff changeset
   160
     */
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26510
diff changeset
   161
    private static final int COMPILE_UNIT_NAME_BUFFER_SIZE = 32;
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26510
diff changeset
   162
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26510
diff changeset
   163
    /**
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   164
     * Compilation phases that a compilation goes through
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   165
     */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   166
    public static class CompilationPhases implements Iterable<CompilationPhase> {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   167
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   168
        /**
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   169
         * Singleton that describes compilation up to the phase where a function can be cached.
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   170
         */
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   171
        private final static CompilationPhases COMPILE_UPTO_CACHED = new CompilationPhases(
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   172
                "Common initial phases",
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   173
                CompilationPhase.CONSTANT_FOLDING_PHASE,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   174
                CompilationPhase.LOWERING_PHASE,
32692
8f60bd284bf4 8055917: jdk.nashorn.internal.codegen.CompilationPhase$N should be renamed to proper classes
sundar
parents: 32530
diff changeset
   175
                CompilationPhase.APPLY_SPECIALIZATION_PHASE,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   176
                CompilationPhase.SPLITTING_PHASE,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   177
                CompilationPhase.PROGRAM_POINT_PHASE,
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   178
                CompilationPhase.SYMBOL_ASSIGNMENT_PHASE,
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   179
                CompilationPhase.SCOPE_DEPTH_COMPUTATION_PHASE,
32692
8f60bd284bf4 8055917: jdk.nashorn.internal.codegen.CompilationPhase$N should be renamed to proper classes
sundar
parents: 32530
diff changeset
   180
                CompilationPhase.CACHE_AST_PHASE
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   181
                );
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   182
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   183
        private final static CompilationPhases COMPILE_CACHED_UPTO_BYTECODE = new CompilationPhases(
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   184
                "After common phases, before bytecode generator",
32692
8f60bd284bf4 8055917: jdk.nashorn.internal.codegen.CompilationPhase$N should be renamed to proper classes
sundar
parents: 32530
diff changeset
   185
                CompilationPhase.DECLARE_LOCAL_SYMBOLS_PHASE,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   186
                CompilationPhase.OPTIMISTIC_TYPE_ASSIGNMENT_PHASE,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   187
                CompilationPhase.LOCAL_VARIABLE_TYPE_CALCULATION_PHASE
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   188
                );
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   189
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   190
        /**
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   191
         * Singleton that describes additional steps to be taken after retrieving a cached function, all the
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   192
         * way up to (but not including) generating and installing code.
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   193
         */
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   194
        public final static CompilationPhases RECOMPILE_CACHED_UPTO_BYTECODE = new CompilationPhases(
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   195
                "Recompile cached function up to bytecode",
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   196
                CompilationPhase.REINITIALIZE_CACHED,
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   197
                COMPILE_CACHED_UPTO_BYTECODE
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   198
                );
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   199
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   200
        /**
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   201
         * Singleton that describes back end of method generation, given that we have generated the normal
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   202
         * method up to CodeGenerator as in {@link CompilationPhases#COMPILE_UPTO_BYTECODE}
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   203
         */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   204
        public final static CompilationPhases GENERATE_BYTECODE_AND_INSTALL = new CompilationPhases(
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   205
                "Generate bytecode and install",
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   206
                CompilationPhase.BYTECODE_GENERATION_PHASE,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   207
                CompilationPhase.INSTALL_PHASE
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   208
                );
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   209
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   210
        /** Singleton that describes compilation up to the CodeGenerator, but not actually generating code */
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   211
        public final static CompilationPhases COMPILE_UPTO_BYTECODE = new CompilationPhases(
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   212
                "Compile upto bytecode",
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   213
                COMPILE_UPTO_CACHED,
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   214
                COMPILE_CACHED_UPTO_BYTECODE);
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   215
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   216
        /** Singleton that describes a standard eager compilation, but no installation, for example used by --compile-only */
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   217
        public final static CompilationPhases COMPILE_ALL_NO_INSTALL = new CompilationPhases(
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   218
                "Compile without install",
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   219
                COMPILE_UPTO_BYTECODE,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   220
                CompilationPhase.BYTECODE_GENERATION_PHASE);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   221
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   222
        /** Singleton that describes a standard eager compilation - this includes code installation */
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   223
        public final static CompilationPhases COMPILE_ALL = new CompilationPhases(
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   224
                "Full eager compilation",
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   225
                COMPILE_UPTO_BYTECODE,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   226
                GENERATE_BYTECODE_AND_INSTALL);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   227
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   228
        /** Singleton that describes a full compilation - this includes code installation - from serialized state*/
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   229
        public final static CompilationPhases COMPILE_ALL_CACHED = new CompilationPhases(
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   230
                "Eager compilation from serializaed state",
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   231
                RECOMPILE_CACHED_UPTO_BYTECODE,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   232
                GENERATE_BYTECODE_AND_INSTALL);
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   233
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   234
        /**
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   235
         * Singleton that describes restOf method generation, given that we have generated the normal
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   236
         * method up to CodeGenerator as in {@link CompilationPhases#COMPILE_UPTO_BYTECODE}
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   237
         */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   238
        public final static CompilationPhases GENERATE_BYTECODE_AND_INSTALL_RESTOF = new CompilationPhases(
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   239
                "Generate bytecode and install - RestOf method",
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   240
                CompilationPhase.REUSE_COMPILE_UNITS_PHASE,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   241
                GENERATE_BYTECODE_AND_INSTALL);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   242
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   243
        /** Compile all for a rest of method */
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   244
        public final static CompilationPhases COMPILE_ALL_RESTOF = new CompilationPhases(
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   245
                "Compile all, rest of",
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   246
                COMPILE_UPTO_BYTECODE,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   247
                GENERATE_BYTECODE_AND_INSTALL_RESTOF);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   248
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   249
        /** Compile from serialized for a rest of method */
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   250
        public final static CompilationPhases COMPILE_CACHED_RESTOF = new CompilationPhases(
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   251
                "Compile serialized, rest of",
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   252
                RECOMPILE_CACHED_UPTO_BYTECODE,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   253
                GENERATE_BYTECODE_AND_INSTALL_RESTOF);
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   254
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   255
        private final List<CompilationPhase> phases;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   256
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   257
        private final String desc;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   258
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   259
        private CompilationPhases(final String desc, final CompilationPhase... phases) {
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   260
            this(desc, Arrays.asList(phases));
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   261
        }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   262
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   263
        private CompilationPhases(final String desc, final CompilationPhases base, final CompilationPhase... phases) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   264
            this(desc, concat(base.phases, Arrays.asList(phases)));
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   265
        }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   266
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   267
        private CompilationPhases(final String desc, final CompilationPhase first, final CompilationPhases rest) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   268
            this(desc, concat(Collections.singletonList(first), rest.phases));
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   269
        }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   270
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   271
        private CompilationPhases(final String desc, final CompilationPhases base) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   272
            this(desc, base.phases);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   273
        }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   274
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   275
        private CompilationPhases(final String desc, final CompilationPhases... bases) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   276
            this(desc, concatPhases(bases));
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   277
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   278
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   279
        private CompilationPhases(final String desc, final List<CompilationPhase> phases) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   280
            this.desc = desc;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   281
            this.phases = phases;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   282
        }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   283
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   284
        private static List<CompilationPhase> concatPhases(final CompilationPhases[] bases) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   285
            final ArrayList<CompilationPhase> l = new ArrayList<>();
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   286
            for(final CompilationPhases base: bases) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   287
                l.addAll(base.phases);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   288
            }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   289
            l.trimToSize();
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   290
            return l;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   291
        }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   292
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   293
        private static <T> List<T> concat(final List<T> l1, final List<T> l2) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   294
            final ArrayList<T> l = new ArrayList<>(l1);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   295
            l.addAll(l2);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   296
            l.trimToSize();
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   297
            return l;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   298
        }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   299
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   300
        @Override
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   301
        public String toString() {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   302
            return "'" + desc + "' " + phases.toString();
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   303
        }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   304
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   305
        boolean contains(final CompilationPhase phase) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   306
            return phases.contains(phase);
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   307
        }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   308
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   309
        @Override
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   310
        public Iterator<CompilationPhase> iterator() {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   311
            return phases.iterator();
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   312
        }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   313
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   314
        boolean isRestOfCompilation() {
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 31549
diff changeset
   315
            return this == COMPILE_ALL_RESTOF || this == GENERATE_BYTECODE_AND_INSTALL_RESTOF || this == COMPILE_CACHED_RESTOF;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   316
        }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   317
24764
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   318
        String getDesc() {
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   319
            return desc;
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   320
        }
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   321
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   322
        String toString(final String prefix) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   323
            final StringBuilder sb = new StringBuilder();
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   324
            for (final CompilationPhase phase : phases) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   325
                sb.append(prefix).append(phase).append('\n');
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   326
            }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   327
            return sb.toString();
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   328
        }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   329
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   330
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   331
    /**
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   332
     * This array contains names that need to be reserved at the start
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   333
     * of a compile, to avoid conflict with variable names later introduced.
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   334
     * See {@link CompilerConstants} for special names used for structures
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   335
     * during a compile.
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   336
     */
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   337
    private static String[] RESERVED_NAMES = {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   338
        SCOPE.symbolName(),
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   339
        THIS.symbolName(),
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   340
        RETURN.symbolName(),
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   341
        CALLEE.symbolName(),
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   342
        VARARGS.symbolName(),
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   343
        ARGUMENTS.symbolName()
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   344
    };
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   345
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   346
    // per instance
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   347
    private final int compilationId = COMPILATION_ID.getAndIncrement();
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
   348
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   349
    // per instance
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   350
    private final AtomicInteger nextCompileUnitId = new AtomicInteger(0);
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
   351
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   352
    private static final AtomicInteger COMPILATION_ID = new AtomicInteger(0);
16252
3bfe9b68a0fa 8008648: Lazy JIT scope and callee semantics bugfixes. Broke out wallclock timer.
lagergren
parents: 16250
diff changeset
   353
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   354
    /**
32530
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   355
     * Creates a new compiler instance for initial compilation of a script.
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   356
     *
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   357
     * @param installer code installer
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   358
     * @param source    source to compile
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   359
     * @param errors    error manager
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   360
     * @param isStrict  is this a strict compilation
32530
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   361
     * @return a new compiler
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   362
     */
32530
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   363
    public static Compiler forInitialCompilation(
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   364
            final CodeInstaller installer,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   365
            final Source source,
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   366
            final ErrorManager errors,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   367
            final boolean isStrict) {
32530
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   368
        return new Compiler(installer.getContext(), installer, source, errors, isStrict);
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   369
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   370
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   371
    /**
32530
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   372
     * Creates a compiler without a code installer. It can only be used to compile code, not install the
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   373
     * generated classes and as such it is useful only for implementation of {@code --compile-only} command
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   374
     * line option.
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   375
     * @param context  the current context
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   376
     * @param source   source to compile
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   377
     * @param isStrict is this a strict compilation
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   378
     * @return a new compiler
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   379
     */
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   380
    public static Compiler forNoInstallerCompilation(
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   381
            final Context context,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   382
            final Source source,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   383
            final boolean isStrict) {
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   384
        return new Compiler(context, null, source, context.getErrorManager(), isStrict);
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   385
    }
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   386
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   387
    /**
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   388
     * Creates a compiler for an on-demand compilation job.
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   389
     *
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   390
     * @param installer                code installer
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   391
     * @param source                   source to compile
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   392
     * @param isStrict                 is this a strict compilation
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   393
     * @param compiledFunction         compiled function, if any
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   394
     * @param types                    parameter and return value type information, if any is known
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   395
     * @param invalidatedProgramPoints invalidated program points for recompilation
25236
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   396
     * @param typeInformationFile      descriptor of the location where type information is persisted
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   397
     * @param continuationEntryPoints  continuation entry points for restof method
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   398
     * @param runtimeScope             runtime scope for recompilation type lookup in {@code TypeEvaluator}
32530
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   399
     * @return a new compiler
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   400
     */
32530
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   401
    public static Compiler forOnDemandCompilation(
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   402
            final CodeInstaller installer,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   403
            final Source source,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   404
            final boolean isStrict,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   405
            final RecompilableScriptFunctionData compiledFunction,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   406
            final TypeMap types,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   407
            final Map<Integer, Type> invalidatedProgramPoints,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   408
            final Object typeInformationFile,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   409
            final int[] continuationEntryPoints,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   410
            final ScriptObject runtimeScope) {
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   411
        final Context context = installer.getContext();
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   412
        return new Compiler(context, installer, source, context.getErrorManager(), isStrict, true,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   413
                compiledFunction, types, invalidatedProgramPoints, typeInformationFile,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   414
                continuationEntryPoints, runtimeScope);
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   415
    }
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   416
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   417
    /**
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   418
     * Convenience constructor for non on-demand compiler instances.
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   419
     */
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   420
    private 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
   421
            final Context context,
32530
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   422
            final CodeInstaller installer,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   423
            final Source source,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   424
            final ErrorManager errors,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   425
            final boolean isStrict) {
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   426
        this(context, installer, source, errors, isStrict, false, null, null, null, null, null, null);
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   427
    }
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   428
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   429
    private Compiler(
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   430
            final Context context,
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   431
            final CodeInstaller installer,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   432
            final Source source,
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   433
            final ErrorManager errors,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   434
            final boolean isStrict,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   435
            final boolean isOnDemand,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   436
            final RecompilableScriptFunctionData compiledFunction,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   437
            final TypeMap types,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   438
            final Map<Integer, Type> invalidatedProgramPoints,
25236
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   439
            final Object typeInformationFile,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   440
            final int[] continuationEntryPoints,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   441
            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
   442
        this.context                  = context;
32530
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   443
        this.env                      = context.getEnv();
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   444
        this.installer                = installer;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   445
        this.constantData             = new ConstantData();
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   446
        this.compileUnits             = CompileUnit.createCompileUnitSet();
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   447
        this.bytecode                 = new LinkedHashMap<>();
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   448
        this.log                      = initLogger(context);
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   449
        this.source                   = source;
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   450
        this.errors                   = errors;
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   451
        this.sourceName               = FunctionNode.getSourceName(source);
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   452
        this.onDemand                 = isOnDemand;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   453
        this.compiledFunction         = compiledFunction;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   454
        this.types                    = types;
32530
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   455
        this.invalidatedProgramPoints = invalidatedProgramPoints == null ? new HashMap<>() : invalidatedProgramPoints;
25236
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   456
        this.typeInformationFile      = typeInformationFile;
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
        this.continuationEntryPoints  = continuationEntryPoints == null ? null: continuationEntryPoints.clone();
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   458
        this.typeEvaluator            = new TypeEvaluator(this, runtimeScope);
24764
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   459
        this.firstCompileUnitName     = firstCompileUnitName();
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   460
        this.strict                   = isStrict;
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   461
24779
3bf490e146c3 8044502: Get rid of global optimistic flag
attila
parents: 24778
diff changeset
   462
        this.optimistic = env._optimistic_types;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   463
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   464
32530
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   465
    private String safeSourceName() {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   466
        String baseName = new File(source.getName()).getName();
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   467
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   468
        final int index = baseName.lastIndexOf(".js");
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   469
        if (index != -1) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   470
            baseName = baseName.substring(0, index);
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   471
        }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   472
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   473
        baseName = baseName.replace('.', '_').replace('-', '_');
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   474
        if (!env._loader_per_compile) {
31549
b627094c5649 8130734: Apply transformations found by netbeans Refactor->Inspect and transform menu
sundar
parents: 31280
diff changeset
   475
            baseName += installer.getUniqueScriptId();
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   476
        }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   477
27106
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   478
        // ASM's bytecode verifier does not allow JVM allowed safe escapes using '\' as escape char.
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   479
        // While ASM accepts such escapes for method names, field names, it enforces Java identifier
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   480
        // for class names. Workaround that ASM bug here by replacing JVM 'dangerous' chars with '_'
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   481
        // rather than safe encoding using '\'.
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   482
        final String mangled = env._verify_code? replaceDangerChars(baseName) : NameCodec.encode(baseName);
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   483
        return mangled != null ? mangled : baseName;
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   484
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   485
27106
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   486
    private static final String DANGEROUS_CHARS   = "\\/.;:$[]<>";
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   487
    private static String replaceDangerChars(final String name) {
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   488
        final int len = name.length();
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   489
        final StringBuilder buf = new StringBuilder();
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   490
        for (int i = 0; i < len; i++) {
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   491
            final char ch = name.charAt(i);
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   492
            if (DANGEROUS_CHARS.indexOf(ch) != -1) {
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   493
                buf.append('_');
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   494
            } else {
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   495
                buf.append(ch);
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   496
            }
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   497
        }
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   498
        return buf.toString();
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   499
    }
d2d7e511c05c 8060688: Nashorn: Generated script class name fails --verify-code for names with special chars
sundar
parents: 26982
diff changeset
   500
24764
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   501
    private String firstCompileUnitName() {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   502
        final StringBuilder sb = new StringBuilder(SCRIPTS_PACKAGE).
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   503
                append('/').
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   504
                append(CompilerConstants.DEFAULT_SCRIPT_NAME.symbolName()).
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   505
                append('$');
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   506
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   507
        if (isOnDemandCompilation()) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   508
            sb.append(RecompilableScriptFunctionData.RECOMPILATION_PREFIX);
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   509
        }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   510
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   511
        if (compilationId > 0) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   512
            sb.append(compilationId).append('$');
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   513
        }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   514
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   515
        if (types != null && compiledFunction.getFunctionNodeId() > 0) {
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   516
            sb.append(compiledFunction.getFunctionNodeId());
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   517
            final Type[] paramTypes = types.getParameterTypes(compiledFunction.getFunctionNodeId());
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   518
            for (final Type t : paramTypes) {
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   519
                sb.append(Type.getShortSignatureDescriptor(t));
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   520
            }
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   521
            sb.append('$');
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   522
        }
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   523
32530
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   524
        sb.append(safeSourceName());
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   525
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   526
        return sb.toString();
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
   527
    }
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
   528
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   529
    void declareLocalSymbol(final String symbolName) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   530
        typeEvaluator.declareLocalSymbol(symbolName);
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   531
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   532
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   533
    void setData(final RecompilableScriptFunctionData data) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   534
        assert this.compiledFunction == null : data;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   535
        this.compiledFunction = data;
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: 16275
diff changeset
   536
    }
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: 16275
diff changeset
   537
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   538
    @Override
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   539
    public DebugLogger getLogger() {
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   540
        return log;
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   541
    }
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   542
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   543
    @Override
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   544
    public DebugLogger initLogger(final Context ctxt) {
26982
ff5dd57a40f2 8059811: Turn off optimistic typing by default and add both ant test-pessimistic and ant test-optimistic sub-test suites.
lagergren
parents: 26979
diff changeset
   545
        final boolean optimisticTypes = env._optimistic_types;
ff5dd57a40f2 8059811: Turn off optimistic typing by default and add both ant test-pessimistic and ant test-optimistic sub-test suites.
lagergren
parents: 26979
diff changeset
   546
        final boolean lazyCompilation = env._lazy_compilation;
ff5dd57a40f2 8059811: Turn off optimistic typing by default and add both ant test-pessimistic and ant test-optimistic sub-test suites.
lagergren
parents: 26979
diff changeset
   547
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: 24779
diff changeset
   548
        return ctxt.getLogger(this.getClass(), new Consumer<DebugLogger>() {
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: 24779
diff changeset
   549
            @Override
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: 24779
diff changeset
   550
            public void accept(final DebugLogger newLogger) {
26982
ff5dd57a40f2 8059811: Turn off optimistic typing by default and add both ant test-pessimistic and ant test-optimistic sub-test suites.
lagergren
parents: 26979
diff changeset
   551
                if (!lazyCompilation) {
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: 24779
diff changeset
   552
                    newLogger.warning("WARNING: Running with lazy compilation switched off. This is not a default setting.");
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: 24779
diff changeset
   553
                }
26979
e02bc4217ece 8059231: Verify that octane raytrace now works with optimistic types turned off. Add better logging for optimistic types in the compiler.
lagergren
parents: 26887
diff changeset
   554
                newLogger.warning("Optimistic types are ", optimisticTypes ? "ENABLED." : "DISABLED.");
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: 24779
diff changeset
   555
            }
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: 24779
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
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   558
24764
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   559
    ScriptEnvironment getScriptEnvironment() {
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   560
        return env;
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   561
    }
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   562
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   563
    boolean isOnDemandCompilation() {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   564
        return onDemand;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   565
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   566
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   567
    boolean useOptimisticTypes() {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   568
        return optimistic;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   569
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   570
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   571
    Context getContext() {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   572
        return context;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   573
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   574
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   575
    Type getOptimisticType(final Optimistic node) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   576
        return typeEvaluator.getOptimisticType(node);
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   577
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   578
26507
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
   579
    /**
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
   580
     * Returns true if the expression can be safely evaluated, and its value is an object known to always use
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
   581
     * String as the type of its property names retrieved through
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
   582
     * {@link ScriptRuntime#toPropertyIterator(Object)}. It is used to avoid optimistic assumptions about its
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
   583
     * property name types.
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
   584
     * @param expr the expression to test
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
   585
     * @return true if the expression can be safely evaluated, and its value is an object known to always use
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
   586
     * String as the type of its property iterators.
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
   587
     */
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
   588
    boolean hasStringPropertyIterator(final Expression expr) {
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
   589
        return typeEvaluator.hasStringPropertyIterator(expr);
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
   590
    }
9d6e3ec59878 8034954: Optimistic iteration in for-in and for-each
attila
parents: 26506
diff changeset
   591
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   592
    void addInvalidatedProgramPoint(final int programPoint, final Type type) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   593
        invalidatedProgramPoints.put(programPoint, type);
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   594
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   595
25236
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   596
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   597
    /**
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   598
     * Returns a copy of this compiler's current mapping of invalidated optimistic program points to their types. The
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   599
     * copy is not live with regard to changes in state in this compiler instance, and is mutable.
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   600
     * @return a copy of this compiler's current mapping of invalidated optimistic program points to their types.
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   601
     */
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   602
    public Map<Integer, Type> getInvalidatedProgramPoints() {
30056
06d201382b55 8053905: Eager code generation fails for earley boyer with split threshold set to 1000
hannesw
parents: 27361
diff changeset
   603
        return invalidatedProgramPoints.isEmpty() ? null : new TreeMap<>(invalidatedProgramPoints);
25236
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   604
    }
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   605
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   606
    TypeMap getTypeMap() {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   607
        return types;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   608
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   609
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   610
    MethodType getCallSiteType(final FunctionNode fn) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   611
        if (types == null || !isOnDemandCompilation()) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   612
            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
   613
        }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   614
        return types.getCallSiteType(fn);
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   615
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   616
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   617
    Type getParamType(final FunctionNode fn, final int pos) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   618
        return types == null ? null : types.get(fn, pos);
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   619
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   620
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   621
    /**
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   622
     * Do a compilation job
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   623
     *
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   624
     * @param functionNode function node to compile
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   625
     * @param phases phases of compilation transforms to apply to function
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   626
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   627
     * @return transformed function
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   628
     *
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   629
     * @throws CompilationException if error occurs during compilation
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   630
     */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   631
    public FunctionNode compile(final FunctionNode functionNode, final CompilationPhases phases) throws CompilationException {
26979
e02bc4217ece 8059231: Verify that octane raytrace now works with optimistic types turned off. Add better logging for optimistic types in the compiler.
lagergren
parents: 26887
diff changeset
   632
        if (log.isEnabled()) {
26982
ff5dd57a40f2 8059811: Turn off optimistic typing by default and add both ant test-pessimistic and ant test-optimistic sub-test suites.
lagergren
parents: 26979
diff changeset
   633
            log.info(">> Starting compile job for ", DebugLogger.quote(functionNode.getName()), " phases=", quote(phases.getDesc()));
26979
e02bc4217ece 8059231: Verify that octane raytrace now works with optimistic types turned off. Add better logging for optimistic types in the compiler.
lagergren
parents: 26887
diff changeset
   634
            log.indent();
e02bc4217ece 8059231: Verify that octane raytrace now works with optimistic types turned off. Add better logging for optimistic types in the compiler.
lagergren
parents: 26887
diff changeset
   635
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   636
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   637
        final String name = DebugLogger.quote(functionNode.getName());
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   638
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
   639
        FunctionNode newFunctionNode = functionNode;
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   640
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   641
        for (final String reservedName : RESERVED_NAMES) {
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
   642
            newFunctionNode.uniqueName(reservedName);
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   643
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   644
31280
72165cb7fd7f 8129959: DebugLogger has unnecessary API methods
attila
parents: 31195
diff changeset
   645
        final boolean info = log.isLoggable(Level.INFO);
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   646
24764
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   647
        final DebugLogger timeLogger = env.isTimingEnabled() ? env._timing.getLogger() : null;
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: 16275
diff changeset
   648
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: 16275
diff changeset
   649
        long time = 0L;
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: 16275
diff changeset
   650
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   651
        for (final CompilationPhase phase : phases) {
26979
e02bc4217ece 8059231: Verify that octane raytrace now works with optimistic types turned off. Add better logging for optimistic types in the compiler.
lagergren
parents: 26887
diff changeset
   652
            log.fine(phase, " starting for ", name);
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   653
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   654
            try {
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   655
                newFunctionNode = phase.apply(this, phases, newFunctionNode);
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   656
            } catch (final ParserException error) {
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   657
                errors.error(error);
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   658
                if (env._dump_on_error) {
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   659
                    error.printStackTrace(env.getErr());
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   660
                }
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   661
                return null;
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   662
            }
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26068
diff changeset
   663
24764
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   664
            log.fine(phase, " done for function ", quote(name));
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: 16275
diff changeset
   665
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   666
            if (env._print_mem_usage) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   667
                printMemoryUsage(functionNode, phase.toString());
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   668
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   669
24764
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   670
            time += (env.isTimingEnabled() ? phase.getEndTime() - phase.getStartTime() : 0L);
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   671
        }
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: 16275
diff changeset
   672
25821
fbb51e67d2a7 8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents: 25241
diff changeset
   673
        if (typeInformationFile != null && !phases.isRestOfCompilation()) {
25236
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   674
            OptimisticTypesPersistence.store(typeInformationFile, invalidatedProgramPoints);
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   675
        }
fac419f1e889 8046921: Deoptimization type information peristence
attila
parents: 24993
diff changeset
   676
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   677
        log.unindent();
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: 16275
diff changeset
   678
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: 16275
diff changeset
   679
        if (info) {
26982
ff5dd57a40f2 8059811: Turn off optimistic typing by default and add both ant test-pessimistic and ant test-optimistic sub-test suites.
lagergren
parents: 26979
diff changeset
   680
            final StringBuilder sb = new StringBuilder("<< Finished compile job for ");
26979
e02bc4217ece 8059231: Verify that octane raytrace now works with optimistic types turned off. Add better logging for optimistic types in the compiler.
lagergren
parents: 26887
diff changeset
   681
            sb.append(newFunctionNode.getSource()).
31280
72165cb7fd7f 8129959: DebugLogger has unnecessary API methods
attila
parents: 31195
diff changeset
   682
            append(':').
72165cb7fd7f 8129959: DebugLogger has unnecessary API methods
attila
parents: 31195
diff changeset
   683
            append(quote(newFunctionNode.getName()));
26979
e02bc4217ece 8059231: Verify that octane raytrace now works with optimistic types turned off. Add better logging for optimistic types in the compiler.
lagergren
parents: 26887
diff changeset
   684
24764
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   685
            if (time > 0L && timeLogger != null) {
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   686
                assert env.isTimingEnabled();
722a9603b237 8043633: In order to remove global state outside of contexts, make sure Timing class is an instance and not a static global collection of data. Move into Context. Move -Dnashorn.timing to an official logging option.
lagergren
parents: 24759
diff changeset
   687
                sb.append(" in ").append(time).append(" ms");
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: 16275
diff changeset
   688
            }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   689
            log.info(sb);
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: 16275
diff changeset
   690
        }
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: 16275
diff changeset
   691
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
   692
        return newFunctionNode;
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: 16275
diff changeset
   693
    }
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: 16275
diff changeset
   694
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   695
    Source getSource() {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   696
        return source;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   697
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   698
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   699
    Map<String, byte[]> getBytecode() {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   700
        return Collections.unmodifiableMap(bytecode);
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   701
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   702
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   703
    /**
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   704
     * Reset bytecode cache for compiler reuse.
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   705
     */
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   706
    void clearBytecode() {
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   707
        bytecode.clear();
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   708
    }
16525
1409942e618e 8009982: Lazy execution bugfix. Added lazy sunspider unit test. Added mandreel to compile-octane test. Fixed warnings
lagergren
parents: 16523
diff changeset
   709
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   710
    CompileUnit getFirstCompileUnit() {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   711
        assert !compileUnits.isEmpty();
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   712
        return compileUnits.iterator().next();
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   713
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   714
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   715
    Set<CompileUnit> getCompileUnits() {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   716
        return compileUnits;
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   717
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   718
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   719
    ConstantData getConstantData() {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   720
        return constantData;
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   721
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   722
32530
20aa15248117 8135262: Sanitize CodeInstaller API
attila
parents: 32435
diff changeset
   723
    CodeInstaller getCodeInstaller() {
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   724
        return installer;
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   725
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   726
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   727
    void addClass(final String name, final byte[] code) {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   728
        bytecode.put(name, code);
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   729
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   730
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   731
    String nextCompileUnitName() {
26887
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26510
diff changeset
   732
        final StringBuilder sb = new StringBuilder(COMPILE_UNIT_NAME_BUFFER_SIZE);
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26510
diff changeset
   733
        sb.append(firstCompileUnitName);
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   734
        final int cuid = nextCompileUnitId.getAndIncrement();
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   735
        if (cuid > 0) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   736
            sb.append("$cu").append(cuid);
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   737
        }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   738
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   739
        return sb.toString();
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   740
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   741
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   742
    /**
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   743
     * Persist current compilation with the given {@code cacheKey}.
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   744
     * @param cacheKey cache key
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   745
     * @param functionNode function node
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   746
     */
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   747
    public void persistClassInfo(final String cacheKey, final FunctionNode functionNode) {
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   748
        if (cacheKey != null && env._persistent_cache) {
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   749
            // If this is an on-demand compilation create a function initializer for the function being compiled.
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   750
            // Otherwise use function initializer map generated by codegen.
31280
72165cb7fd7f 8129959: DebugLogger has unnecessary API methods
attila
parents: 31195
diff changeset
   751
            final Map<Integer, FunctionInitializer> initializers = new HashMap<>();
30056
06d201382b55 8053905: Eager code generation fails for earley boyer with split threshold set to 1000
hannesw
parents: 27361
diff changeset
   752
            if (isOnDemandCompilation()) {
06d201382b55 8053905: Eager code generation fails for earley boyer with split threshold set to 1000
hannesw
parents: 27361
diff changeset
   753
                initializers.put(functionNode.getId(), new FunctionInitializer(functionNode, getInvalidatedProgramPoints()));
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   754
            } else {
30056
06d201382b55 8053905: Eager code generation fails for earley boyer with split threshold set to 1000
hannesw
parents: 27361
diff changeset
   755
                for (final CompileUnit compileUnit : getCompileUnits()) {
06d201382b55 8053905: Eager code generation fails for earley boyer with split threshold set to 1000
hannesw
parents: 27361
diff changeset
   756
                    for (final FunctionNode fn : compileUnit.getFunctionNodes()) {
06d201382b55 8053905: Eager code generation fails for earley boyer with split threshold set to 1000
hannesw
parents: 27361
diff changeset
   757
                        initializers.put(fn.getId(), new FunctionInitializer(fn));
06d201382b55 8053905: Eager code generation fails for earley boyer with split threshold set to 1000
hannesw
parents: 27361
diff changeset
   758
                    }
06d201382b55 8053905: Eager code generation fails for earley boyer with split threshold set to 1000
hannesw
parents: 27361
diff changeset
   759
                }
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   760
            }
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   761
            final String mainClassName = getFirstCompileUnit().getUnitClassName();
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   762
            installer.storeScript(cacheKey, source, mainClassName, bytecode, initializers, constantData.toArray(), compilationId);
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   763
        }
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   764
    }
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   765
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   766
    /**
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   767
     * Make sure the next compilation id is greater than {@code value}.
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   768
     * @param value compilation id value
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   769
     */
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   770
    public static void updateCompilationId(final int value) {
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   771
        if (value >= COMPILATION_ID.get()) {
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   772
            COMPILATION_ID.set(value + 1);
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   773
        }
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   774
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   775
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   776
    CompileUnit addCompileUnit(final long initialWeight) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   777
        final CompileUnit compileUnit = createCompileUnit(initialWeight);
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   778
        compileUnits.add(compileUnit);
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   779
        log.fine("Added compile unit ", compileUnit);
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   780
        return compileUnit;
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   781
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   782
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   783
    CompileUnit createCompileUnit(final String unitClassName, final long initialWeight) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   784
        final ClassEmitter classEmitter = new ClassEmitter(context, sourceName, unitClassName, isStrict());
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   785
        final CompileUnit  compileUnit  = new CompileUnit(unitClassName, classEmitter, initialWeight);
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   786
        classEmitter.begin();
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   787
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   788
        return compileUnit;
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   789
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   790
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   791
    private CompileUnit createCompileUnit(final long initialWeight) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   792
        return createCompileUnit(nextCompileUnitName(), initialWeight);
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   793
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   794
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   795
    boolean isStrict() {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   796
        return strict;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   797
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   798
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   799
    void replaceCompileUnits(final Set<CompileUnit> newUnits) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   800
        compileUnits.clear();
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   801
        compileUnits.addAll(newUnits);
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   802
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   803
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   804
    CompileUnit findUnit(final long weight) {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   805
        for (final CompileUnit unit : compileUnits) {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   806
            if (unit.canHold(weight)) {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   807
                unit.addWeight(weight);
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   808
                return unit;
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   809
            }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   810
        }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   811
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   812
        return addCompileUnit(weight);
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   813
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   814
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   815
    /**
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   816
     * Convert a package/class name to a binary name.
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   817
     *
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   818
     * @param name Package/class name.
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   819
     * @return Binary name.
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   820
     */
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   821
    public static String binaryName(final String name) {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   822
        return name.replace('/', '.');
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   823
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   824
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   825
    RecompilableScriptFunctionData getScriptFunctionData(final int functionId) {
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   826
        assert compiledFunction != null;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   827
        final RecompilableScriptFunctionData fn = compiledFunction.getScriptFunctionData(functionId);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   828
        assert fn != null : functionId;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27106
diff changeset
   829
        return fn;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   830
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   831
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   832
    boolean isGlobalSymbol(final FunctionNode fn, final String name) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   833
        return getScriptFunctionData(fn.getId()).isGlobalSymbol(fn, name);
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   834
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   835
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   836
    int[] getContinuationEntryPoints() {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   837
        return continuationEntryPoints;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   838
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   839
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   840
    Type getInvalidatedProgramPointType(final int programPoint) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   841
        return invalidatedProgramPoints.get(programPoint);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   842
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   843
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   844
    private void printMemoryUsage(final FunctionNode functionNode, final String phaseName) {
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   845
        if (!log.isEnabled()) {
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: 24722
diff changeset
   846
            return;
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: 24722
diff changeset
   847
        }
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: 24722
diff changeset
   848
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   849
        log.info(phaseName, "finished. Doing IR size calculation...");
17527
6e45d9c2328c 8014329: Slim down the label stack structure in CodeGenerator
lagergren
parents: 17525
diff changeset
   850
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   851
        final ObjectSizeCalculator osc = new ObjectSizeCalculator(ObjectSizeCalculator.getEffectiveMemoryLayoutSpecification());
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   852
        osc.calculateObjectSize(functionNode);
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   853
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: 24722
diff changeset
   854
        final List<ClassHistogramElement> list      = osc.getClassHistogram();
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: 24722
diff changeset
   855
        final StringBuilder               sb        = new StringBuilder();
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: 24722
diff changeset
   856
        final long                        totalSize = osc.calculateObjectSize(functionNode);
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   857
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: 24722
diff changeset
   858
        sb.append(phaseName).
31280
72165cb7fd7f 8129959: DebugLogger has unnecessary API methods
attila
parents: 31195
diff changeset
   859
        append(" Total size = ").
72165cb7fd7f 8129959: DebugLogger has unnecessary API methods
attila
parents: 31195
diff changeset
   860
        append(totalSize / 1024 / 1024).
72165cb7fd7f 8129959: DebugLogger has unnecessary API methods
attila
parents: 31195
diff changeset
   861
        append("MB");
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   862
        log.info(sb);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   863
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   864
        Collections.sort(list, new Comparator<ClassHistogramElement>() {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   865
            @Override
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: 24722
diff changeset
   866
            public int compare(final ClassHistogramElement o1, final ClassHistogramElement o2) {
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   867
                final long diff = o1.getBytes() - o2.getBytes();
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   868
                if (diff < 0) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   869
                    return 1;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   870
                } else if (diff > 0) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   871
                    return -1;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   872
                } else {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   873
                    return 0;
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   874
                }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   875
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   876
        });
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   877
        for (final ClassHistogramElement e : list) {
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   878
            final String line = String.format("    %-48s %10d bytes (%8d instances)", e.getClazz(), e.getBytes(), e.getInstances());
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   879
            log.info(line);
17527
6e45d9c2328c 8014329: Slim down the label stack structure in CodeGenerator
lagergren
parents: 17525
diff changeset
   880
            if (e.getBytes() < totalSize / 200) {
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   881
                log.info("    ...");
17519
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   882
                break; // never mind, so little memory anyway
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   883
            }
19c9d2553e35 8013871: mem usage histograms enabled with compiler logging level set to more specific than or equals to info when --print-mem-usage flag is used
lagergren
parents: 17518
diff changeset
   884
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   885
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   886
}