nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/MethodEmitter.java
author sundar
Tue, 04 Aug 2015 18:18:54 +0530
changeset 32048 8023426b93ab
parent 30391 62dcad329b26
child 32534 b3ec7f3b3c2a
permissions -rw-r--r--
8073733: TypeError messages with "call" and "new" could be improved Reviewed-by: attila, mhaupt
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
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    28
import static jdk.internal.org.objectweb.asm.Opcodes.ATHROW;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    29
import static jdk.internal.org.objectweb.asm.Opcodes.CHECKCAST;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    30
import static jdk.internal.org.objectweb.asm.Opcodes.DUP2;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    31
import static jdk.internal.org.objectweb.asm.Opcodes.GETFIELD;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    32
import static jdk.internal.org.objectweb.asm.Opcodes.GETSTATIC;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    33
import static jdk.internal.org.objectweb.asm.Opcodes.GOTO;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    34
import static jdk.internal.org.objectweb.asm.Opcodes.H_INVOKESTATIC;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    35
import static jdk.internal.org.objectweb.asm.Opcodes.IFEQ;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    36
import static jdk.internal.org.objectweb.asm.Opcodes.IFGE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    37
import static jdk.internal.org.objectweb.asm.Opcodes.IFGT;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    38
import static jdk.internal.org.objectweb.asm.Opcodes.IFLE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    39
import static jdk.internal.org.objectweb.asm.Opcodes.IFLT;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    40
import static jdk.internal.org.objectweb.asm.Opcodes.IFNE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    41
import static jdk.internal.org.objectweb.asm.Opcodes.IFNONNULL;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    42
import static jdk.internal.org.objectweb.asm.Opcodes.IFNULL;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    43
import static jdk.internal.org.objectweb.asm.Opcodes.IF_ACMPEQ;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    44
import static jdk.internal.org.objectweb.asm.Opcodes.IF_ACMPNE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    45
import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPEQ;
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
    46
import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPGE;
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
    47
import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPGT;
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
    48
import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPLE;
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
    49
import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPLT;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
    50
import static jdk.internal.org.objectweb.asm.Opcodes.IF_ICMPNE;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    51
import static jdk.internal.org.objectweb.asm.Opcodes.INSTANCEOF;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    52
import static jdk.internal.org.objectweb.asm.Opcodes.INVOKEINTERFACE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    53
import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESPECIAL;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    54
import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESTATIC;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    55
import static jdk.internal.org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    56
import static jdk.internal.org.objectweb.asm.Opcodes.NEW;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    57
import static jdk.internal.org.objectweb.asm.Opcodes.PUTFIELD;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    58
import static jdk.internal.org.objectweb.asm.Opcodes.PUTSTATIC;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    59
import static jdk.internal.org.objectweb.asm.Opcodes.RETURN;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    60
import static jdk.nashorn.internal.codegen.CompilerConstants.ARGUMENTS;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    61
import static jdk.nashorn.internal.codegen.CompilerConstants.CONSTANTS;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    62
import static jdk.nashorn.internal.codegen.CompilerConstants.SCOPE;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    63
import static jdk.nashorn.internal.codegen.CompilerConstants.THIS;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    64
import static jdk.nashorn.internal.codegen.CompilerConstants.THIS_DEBUGGER;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    65
import static jdk.nashorn.internal.codegen.CompilerConstants.VARARGS;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    66
import static jdk.nashorn.internal.codegen.CompilerConstants.className;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    67
import static jdk.nashorn.internal.codegen.CompilerConstants.constructorNoLookup;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    68
import static jdk.nashorn.internal.codegen.CompilerConstants.methodDescriptor;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    69
import static jdk.nashorn.internal.codegen.CompilerConstants.staticField;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    70
import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCallNoLookup;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
    71
import static jdk.nashorn.internal.codegen.ObjectClassGenerator.PRIMITIVE_FIELD_TYPE;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
    72
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_OPTIMISTIC;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
    73
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_PROGRAM_POINT_SHIFT;
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27099
diff changeset
    74
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    75
import java.io.PrintStream;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    76
import java.lang.reflect.Array;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
    77
import java.util.Collection;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    78
import java.util.EnumSet;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
    79
import java.util.IdentityHashMap;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    80
import java.util.List;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
    81
import java.util.Map;
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents: 16225
diff changeset
    82
import jdk.internal.dynalink.support.NameCodec;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    83
import jdk.internal.org.objectweb.asm.Handle;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    84
import jdk.internal.org.objectweb.asm.MethodVisitor;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    85
import jdk.nashorn.internal.codegen.ClassEmitter.Flag;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    86
import jdk.nashorn.internal.codegen.CompilerConstants.Call;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    87
import jdk.nashorn.internal.codegen.CompilerConstants.FieldAccess;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    88
import jdk.nashorn.internal.codegen.types.ArrayType;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    89
import jdk.nashorn.internal.codegen.types.BitwiseType;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    90
import jdk.nashorn.internal.codegen.types.NumericType;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    91
import jdk.nashorn.internal.codegen.types.Type;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    92
import jdk.nashorn.internal.ir.FunctionNode;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    93
import jdk.nashorn.internal.ir.IdentNode;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
    94
import jdk.nashorn.internal.ir.JoinPredecessor;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    95
import jdk.nashorn.internal.ir.LiteralNode;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
    96
import jdk.nashorn.internal.ir.LocalVariableConversion;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    97
import jdk.nashorn.internal.ir.Symbol;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
    98
import jdk.nashorn.internal.ir.TryNode;
27099
eceb216332cb 8050977: Java8 Javascript Nashorn exception: no current Global instance for nashorn
sundar
parents: 26890
diff changeset
    99
import jdk.nashorn.internal.objects.NativeArray;
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   100
import jdk.nashorn.internal.runtime.ArgumentSetter;
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   101
import jdk.nashorn.internal.runtime.Context;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   102
import jdk.nashorn.internal.runtime.Debug;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   103
import jdk.nashorn.internal.runtime.JSType;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   104
import jdk.nashorn.internal.runtime.RewriteException;
26890
fa03d7a7d50e 8059372: Code duplication in split emitter
attila
parents: 26887
diff changeset
   105
import jdk.nashorn.internal.runtime.Scope;
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   106
import jdk.nashorn.internal.runtime.ScriptObject;
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26377
diff changeset
   107
import jdk.nashorn.internal.runtime.ScriptRuntime;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   108
import jdk.nashorn.internal.runtime.UnwarrantedOptimismException;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   109
import jdk.nashorn.internal.runtime.linker.Bootstrap;
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
   110
import jdk.nashorn.internal.runtime.logging.DebugLogger;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   111
import jdk.nashorn.internal.runtime.options.Options;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   112
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   113
/**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   114
 * This is the main function responsible for emitting method code
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   115
 * in a class. It maintains a type stack and keeps track of control
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   116
 * flow to make sure that the registered instructions don't violate
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   117
 * byte code verification.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   118
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   119
 * Running Nashorn with -ea will assert as soon as a type stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   120
 * becomes corrupt, for easier debugging
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   121
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   122
 * Running Nashorn with -Dnashorn.codegen.debug=true will print
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   123
 * all generated bytecode and labels to stderr, for easier debugging,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   124
 * including bytecode stack contents
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   125
 */
30391
62dcad329b26 8079349: Eliminate dead code around Nashorn code generator
attila
parents: 29283
diff changeset
   126
public class MethodEmitter {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   127
    /** The ASM MethodVisitor we are plugged into */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   128
    private final MethodVisitor method;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   129
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   130
    /** Parent classEmitter representing the class of this method */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   131
    private final ClassEmitter classEmitter;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   132
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   133
    /** FunctionNode representing this method, or null if none exists */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   134
    protected FunctionNode functionNode;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   135
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   136
    /** Current type stack for current evaluation */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   137
    private Label.Stack stack;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   138
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   139
    private boolean preventUndefinedLoad;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   140
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   141
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   142
     * Map of live local variable definitions.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   143
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   144
    private final Map<Symbol, LocalVariableDef> localVariableDefs = new IdentityHashMap<>();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   145
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   146
    /** The context */
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   147
    private final Context context;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   148
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   149
    /** Threshold in chars for when string constants should be split */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   150
    static final int LARGE_STRING_THRESHOLD = 32 * 1024;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   151
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   152
    /** Debug flag, should we dump all generated bytecode along with stacks? */
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   153
    private final DebugLogger log;
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   154
    private final boolean     debug;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   155
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   156
    /** dump stack on a particular line, or -1 if disabled */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   157
    private static final int DEBUG_TRACE_LINE;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   158
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   159
    static {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   160
        final String tl = Options.getStringProperty("nashorn.codegen.debug.trace", "-1");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   161
        int line = -1;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   162
        try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   163
            line = Integer.parseInt(tl);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   164
        } catch (final NumberFormatException e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   165
            //fallthru
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   166
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   167
        DEBUG_TRACE_LINE = line;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   168
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   169
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   170
    /** Bootstrap for normal indy:s */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   171
    private static final Handle LINKERBOOTSTRAP  = new Handle(H_INVOKESTATIC, Bootstrap.BOOTSTRAP.className(), Bootstrap.BOOTSTRAP.name(), Bootstrap.BOOTSTRAP.descriptor());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   172
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   173
    /** Bootstrap for array populators */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   174
    private static final Handle POPULATE_ARRAY_BOOTSTRAP = new Handle(H_INVOKESTATIC, RewriteException.BOOTSTRAP.className(), RewriteException.BOOTSTRAP.name(), RewriteException.BOOTSTRAP.descriptor());
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   175
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   176
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   177
     * Constructor - internal use from ClassEmitter only
16154
de44634fa4ec 8005782: get rid of javadoc errors, warnings in nashorn build
sundar
parents: 16151
diff changeset
   178
     * @see ClassEmitter#method
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   179
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   180
     * @param classEmitter the class emitter weaving the class this method is in
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   181
     * @param method       a method visitor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   182
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   183
    MethodEmitter(final ClassEmitter classEmitter, final MethodVisitor method) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   184
        this(classEmitter, method, null);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   185
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   186
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   187
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   188
     * Constructor - internal use from ClassEmitter only
16154
de44634fa4ec 8005782: get rid of javadoc errors, warnings in nashorn build
sundar
parents: 16151
diff changeset
   189
     * @see ClassEmitter#method
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   190
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   191
     * @param classEmitter the class emitter weaving the class this method is in
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   192
     * @param method       a method visitor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   193
     * @param functionNode a function node representing this method
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   194
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   195
    MethodEmitter(final ClassEmitter classEmitter, final MethodVisitor method, final FunctionNode functionNode) {
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   196
        this.context      = classEmitter.getContext();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   197
        this.classEmitter = classEmitter;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   198
        this.method       = method;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   199
        this.functionNode = functionNode;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   200
        this.stack        = null;
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   201
        this.log          = context.getLogger(CodeGenerator.class);
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
   202
        this.debug        = log.isEnabled();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   203
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   204
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   205
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   206
     * Begin a method
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   207
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   208
    public void begin() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   209
        classEmitter.beginMethod(this);
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
   210
        newStack();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   211
        method.visitCode();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   212
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   213
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   214
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   215
     * End a method
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   216
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   217
    public void end() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   218
        method.visitMaxs(0, 0);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   219
        method.visitEnd();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   220
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   221
        classEmitter.endMethod(this);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   222
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   223
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   224
    boolean isReachable() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   225
        return stack != null;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   226
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   227
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   228
    private void doesNotContinueSequentially() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   229
        stack = null;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   230
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   231
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
   232
    private void newStack() {
17527
6e45d9c2328c 8014329: Slim down the label stack structure in CodeGenerator
lagergren
parents: 17524
diff changeset
   233
        stack = new Label.Stack();
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
   234
    }
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
   235
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   236
    @Override
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   237
    public String toString() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   238
        return "methodEmitter: " + (functionNode == null ? method : functionNode.getName()).toString() + ' ' + Debug.id(this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   239
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   240
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   241
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   242
     * Push a type to the existing stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   243
     * @param type the type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   244
     */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   245
    void pushType(final Type type) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   246
        if (type != null) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   247
            stack.push(type);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   248
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   249
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   250
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   251
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   252
     * Pop a type from the existing stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   253
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   254
     * @param expected expected type - will assert if wrong
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   255
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   256
     * @return the type that was retrieved
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   257
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   258
    private Type popType(final Type expected) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   259
        final Type type = popType();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   260
        assert type.isObject() && expected.isObject() ||
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   261
            type.isEquivalentTo(expected) : type + " is not compatible with " + expected;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   262
        return type;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   263
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   264
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   265
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   266
     * Pop a type from the existing stack, no matter what it is.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   267
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   268
     * @return the type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   269
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   270
    private Type popType() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   271
        return stack.pop();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   272
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   273
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   274
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   275
     * Pop a type from the existing stack, ensuring that it is numeric. Boolean type is popped as int type.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   276
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   277
     * @return the type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   278
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   279
    private NumericType popNumeric() {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   280
        final Type type = popType();
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   281
        if(type.isBoolean()) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   282
            // Booleans are treated as int for purposes of arithmetic operations
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   283
            return Type.INT;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   284
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   285
        assert type.isNumeric();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   286
        return (NumericType)type;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   287
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   288
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   289
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   290
     * Pop a type from the existing stack, ensuring that it is an integer type
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   291
     * (integer or long). Boolean type is popped as int type.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   292
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   293
     * @return the type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   294
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   295
    private BitwiseType popBitwise() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   296
        final Type type = popType();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   297
        if(type == Type.BOOLEAN) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   298
            return Type.INT;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   299
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   300
        return (BitwiseType)type;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   301
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   302
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   303
    private BitwiseType popInteger() {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   304
        final Type type = popType();
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   305
        if(type == Type.BOOLEAN) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   306
            return Type.INT;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   307
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   308
        assert type == Type.INT;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   309
        return (BitwiseType)type;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   310
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   311
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   312
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   313
     * Pop a type from the existing stack, ensuring that it is an array type,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   314
     * assert if not
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   315
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   316
     * @return the type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   317
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   318
    private ArrayType popArray() {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   319
        final Type type = popType();
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   320
        assert type.isArray() : type;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   321
        return (ArrayType)type;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   322
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   323
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   324
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   325
     * Peek a given number of slots from the top of the stack and return the
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   326
     * type in that slot
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   327
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   328
     * @param pos the number of positions from the top, 0 is the top element
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   329
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   330
     * @return the type at position "pos" on the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   331
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   332
    final Type peekType(final int pos) {
17527
6e45d9c2328c 8014329: Slim down the label stack structure in CodeGenerator
lagergren
parents: 17524
diff changeset
   333
        return stack.peek(pos);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   334
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   335
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   336
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   337
     * Peek at the type at the top of the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   338
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   339
     * @return the type at the top of the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   340
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   341
    final Type peekType() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   342
        return stack.peek();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   343
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   344
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   345
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   346
     * Generate code a for instantiating a new object and push the
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   347
     * object type on the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   348
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   349
     * @param classDescriptor class descriptor for the object type
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   350
     * @param type the type of the new object
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   351
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   352
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   353
     */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   354
    MethodEmitter _new(final String classDescriptor, final Type type) {
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   355
        debug("new", classDescriptor);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   356
        method.visitTypeInsn(NEW, classDescriptor);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   357
        pushType(type);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   358
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   359
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   360
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   361
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   362
     * Generate code a for instantiating a new object and push the
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   363
     * object type on the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   364
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   365
     * @param clazz class type to instatiate
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   366
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   367
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   368
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   369
    MethodEmitter _new(final Class<?> clazz) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   370
        return _new(className(clazz), Type.typeFor(clazz));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   371
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   372
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   373
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   374
     * Generate code to call the empty constructor for a class
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   375
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   376
     * @param clazz class type to instatiate
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   377
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   378
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   379
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   380
    MethodEmitter newInstance(final Class<?> clazz) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   381
        return invoke(constructorNoLookup(clazz));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   382
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   383
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   384
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   385
     * Perform a dup, that is, duplicate the top element and
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   386
     * push the duplicate down a given number of positions
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   387
     * on the stack. This is totally type agnostic.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   388
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   389
     * @param depth the depth on which to put the copy
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   390
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   391
     * @return the method emitter, or null if depth is illegal and
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   392
     *  has no instruction equivalent.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   393
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   394
    MethodEmitter dup(final int depth) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   395
        if (peekType().dup(method, depth) == null) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   396
            return null;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   397
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   398
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   399
        debug("dup", depth);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   400
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   401
        switch (depth) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   402
        case 0: {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   403
            final int l0 = stack.getTopLocalLoad();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   404
            pushType(peekType());
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   405
            stack.markLocalLoad(l0);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   406
            break;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   407
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   408
        case 1: {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   409
            final int l0 = stack.getTopLocalLoad();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   410
            final Type p0 = popType();
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   411
            final int l1 = stack.getTopLocalLoad();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   412
            final Type p1 = popType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   413
            pushType(p0);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   414
            stack.markLocalLoad(l0);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   415
            pushType(p1);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   416
            stack.markLocalLoad(l1);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   417
            pushType(p0);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   418
            stack.markLocalLoad(l0);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   419
            break;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   420
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   421
        case 2: {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   422
            final int l0 = stack.getTopLocalLoad();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   423
            final Type p0 = popType();
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   424
            final int l1 = stack.getTopLocalLoad();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   425
            final Type p1 = popType();
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   426
            final int l2 = stack.getTopLocalLoad();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   427
            final Type p2 = popType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   428
            pushType(p0);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   429
            stack.markLocalLoad(l0);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   430
            pushType(p2);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   431
            stack.markLocalLoad(l2);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   432
            pushType(p1);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   433
            stack.markLocalLoad(l1);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   434
            pushType(p0);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   435
            stack.markLocalLoad(l0);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   436
            break;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   437
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   438
        default:
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   439
            assert false : "illegal dup depth = " + depth;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   440
            return null;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   441
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   442
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   443
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   444
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   445
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   446
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   447
     * Perform a dup2, that is, duplicate the top element if it
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   448
     * is a category 2 type, or two top elements if they are category
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   449
     * 1 types, and push them on top of the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   450
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   451
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   452
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   453
    MethodEmitter dup2() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   454
        debug("dup2");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   455
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   456
        if (peekType().isCategory2()) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   457
            final int l0 = stack.getTopLocalLoad();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   458
            pushType(peekType());
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   459
            stack.markLocalLoad(l0);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   460
        } else {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   461
            final int l0 = stack.getTopLocalLoad();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   462
            final Type p0 = popType();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   463
            final int l1 = stack.getTopLocalLoad();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   464
            final Type p1 = popType();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   465
            pushType(p0);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   466
            stack.markLocalLoad(l0);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   467
            pushType(p1);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   468
            stack.markLocalLoad(l1);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   469
            pushType(p0);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   470
            stack.markLocalLoad(l0);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   471
            pushType(p1);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   472
            stack.markLocalLoad(l1);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   473
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   474
        method.visitInsn(DUP2);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   475
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   476
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   477
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   478
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   479
     * Duplicate the top element on the stack and push it
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   480
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   481
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   482
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   483
    MethodEmitter dup() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   484
        return dup(0);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   485
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   486
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   487
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   488
     * Pop the top element of the stack and throw it away
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   489
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   490
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   491
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   492
    MethodEmitter pop() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   493
        debug("pop", peekType());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   494
        popType().pop(method);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   495
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   496
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   497
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   498
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   499
     * Pop the top element of the stack if category 2 type, or the two
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   500
     * top elements of the stack if category 1 types
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   501
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   502
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   503
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   504
    MethodEmitter pop2() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   505
        if (peekType().isCategory2()) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   506
            popType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   507
        } else {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   508
            get2n();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   509
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   510
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   511
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   512
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   513
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   514
     * Swap the top two elements of the stack. This is totally
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   515
     * type agnostic and works for all types
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   516
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   517
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   518
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   519
    MethodEmitter swap() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   520
        debug("swap");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   521
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   522
        final int l0 = stack.getTopLocalLoad();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   523
        final Type p0 = popType();
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   524
        final int l1 = stack.getTopLocalLoad();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   525
        final Type p1 = popType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   526
        p0.swap(method, p1);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   527
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   528
        pushType(p0);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   529
        stack.markLocalLoad(l0);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   530
        pushType(p1);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   531
        stack.markLocalLoad(l1);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   532
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   533
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   534
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   535
    void pack() {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   536
        final Type type = peekType();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   537
        if (type.isInteger()) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   538
            convert(PRIMITIVE_FIELD_TYPE);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   539
        } else if (type.isLong()) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   540
            //nop
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   541
        } else if (type.isNumber()) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   542
            invokestatic("java/lang/Double", "doubleToRawLongBits", "(D)J");
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   543
        } else {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   544
            assert false : type + " cannot be packed!";
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   545
        }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   546
        //all others are nops, objects aren't packed
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   547
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   548
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   549
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   550
     * Initializes a bytecode method parameter
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   551
     * @param symbol the symbol for the parameter
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   552
     * @param type the type of the parameter
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   553
     * @param start the label for the start of the method
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   554
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   555
    void initializeMethodParameter(final Symbol symbol, final Type type, final Label start) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   556
        assert symbol.isBytecodeLocal();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   557
        localVariableDefs.put(symbol, new LocalVariableDef(start.getLabel(), type));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   558
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   559
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   560
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   561
     * Create a new string builder, call the constructor and push the instance to the stack.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   562
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   563
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   564
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   565
    MethodEmitter newStringBuilder() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   566
        return invoke(constructorNoLookup(StringBuilder.class)).dup();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   567
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   568
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   569
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   570
     * Pop a string and a StringBuilder from the top of the stack and call the append
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   571
     * function of the StringBuilder, appending the string. Pushes the StringBuilder to
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   572
     * the stack when finished.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   573
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   574
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   575
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   576
    MethodEmitter stringBuilderAppend() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   577
        convert(Type.STRING);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   578
        return invoke(virtualCallNoLookup(StringBuilder.class, "append", StringBuilder.class, String.class));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   579
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   580
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   581
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   582
     * Pops two integer types from the stack, performs a bitwise and and pushes
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   583
     * the result
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   584
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   585
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   586
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   587
    MethodEmitter and() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   588
        debug("and");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   589
        pushType(get2i().and(method));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   590
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   591
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   592
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   593
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   594
     * Pops two integer types from the stack, performs a bitwise or and pushes
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   595
     * the result
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   596
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   597
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   598
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   599
    MethodEmitter or() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   600
        debug("or");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   601
        pushType(get2i().or(method));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   602
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   603
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   604
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   605
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   606
     * Pops two integer types from the stack, performs a bitwise xor and pushes
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   607
     * the result
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   608
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   609
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   610
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   611
    MethodEmitter xor() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   612
        debug("xor");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   613
        pushType(get2i().xor(method));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   614
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   615
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   616
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   617
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   618
     * Pops two integer types from the stack, performs a bitwise logic shift right and pushes
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   619
     * the result. The shift count, the first element, must be INT.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   620
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   621
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   622
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   623
    MethodEmitter shr() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   624
        debug("shr");
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   625
        popInteger();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   626
        pushType(popBitwise().shr(method));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   627
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   628
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   629
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   630
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   631
     * Pops two integer types from the stack, performs a bitwise shift left and and pushes
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   632
     * the result. The shift count, the first element, must be INT.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   633
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   634
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   635
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   636
    MethodEmitter shl() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   637
        debug("shl");
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   638
        popInteger();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   639
        pushType(popBitwise().shl(method));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   640
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   641
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   642
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   643
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   644
     * Pops two integer types from the stack, performs a bitwise arithmetic shift right and pushes
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   645
     * the result. The shift count, the first element, must be INT.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   646
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   647
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   648
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   649
    MethodEmitter sar() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   650
        debug("sar");
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   651
        popInteger();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   652
        pushType(popBitwise().sar(method));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   653
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   654
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   655
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   656
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   657
     * Pops a numeric type from the stack, negates it and pushes the result
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   658
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   659
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   660
     */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   661
    MethodEmitter neg(final int programPoint) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   662
        debug("neg");
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   663
        pushType(popNumeric().neg(method, programPoint));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   664
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   665
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   666
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   667
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   668
     * Add label for the start of a catch block and push the exception to the
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   669
     * stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   670
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   671
     * @param recovery label pointing to start of catch block
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   672
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   673
    void _catch(final Label recovery) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   674
        // While in JVM a catch block can be reached through normal control flow, our code generator never does this,
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   675
        // so we might as well presume there's no stack on entry.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   676
        assert stack == null;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   677
        recovery.onCatch();
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   678
        label(recovery);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   679
        beginCatchBlock();
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   680
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   681
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   682
    /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   683
     * Add any number of labels for the start of a catch block and push the exception to the
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   684
     * stack
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   685
     *
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   686
     * @param recoveries labels pointing to start of catch block
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   687
     */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   688
    void _catch(final Collection<Label> recoveries) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   689
        assert stack == null;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   690
        for(final Label l: recoveries) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   691
            label(l);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   692
        }
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   693
        beginCatchBlock();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   694
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   695
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   696
    private void beginCatchBlock() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   697
        // It can happen that the catch label wasn't marked as reachable. They are marked as reachable if there's an
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   698
        // assignment in the try block, but it's possible that there was none.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   699
        if(!isReachable()) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   700
            newStack();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   701
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   702
        pushType(Type.typeFor(Throwable.class));
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   703
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   704
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   705
     * Start a try/catch block.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   706
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   707
     * @param entry          start label for try
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   708
     * @param exit           end label for try
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   709
     * @param recovery       start label for catch
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   710
     * @param typeDescriptor type descriptor for exception
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   711
     * @param isOptimismHandler true if this is a hander for {@code UnwarrantedOptimismException}. Normally joining on a
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   712
     * catch handler kills temporary variables, but optimism handlers are an exception, as they need to capture
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   713
     * temporaries as well, so they must remain live.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   714
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   715
    private void _try(final Label entry, final Label exit, final Label recovery, final String typeDescriptor, final boolean isOptimismHandler) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   716
        recovery.joinFromTry(entry.getStack(), isOptimismHandler);
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
   717
        method.visitTryCatchBlock(entry.getLabel(), exit.getLabel(), recovery.getLabel(), typeDescriptor);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   718
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   719
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   720
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   721
     * Start a try/catch block.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   722
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   723
     * @param entry    start label for try
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   724
     * @param exit     end label for try
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   725
     * @param recovery start label for catch
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   726
     * @param clazz    exception class
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   727
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   728
    void _try(final Label entry, final Label exit, final Label recovery, final Class<?> clazz) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   729
        _try(entry, exit, recovery, CompilerConstants.className(clazz), clazz == UnwarrantedOptimismException.class);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   730
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   731
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   732
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   733
     * Start a try/catch block. The catch is "Throwable" - i.e. catch-all
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   734
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   735
     * @param entry    start label for try
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   736
     * @param exit     end label for try
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   737
     * @param recovery start label for catch
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   738
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   739
    void _try(final Label entry, final Label exit, final Label recovery) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   740
        _try(entry, exit, recovery, (String)null, false);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   741
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   742
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   743
    void markLabelAsOptimisticCatchHandler(final Label label, final int liveLocalCount) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   744
        label.markAsOptimisticCatchHandler(stack, liveLocalCount);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   745
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   746
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   747
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   748
     * Load the constants array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   749
     * @return this method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   750
     */
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16262
diff changeset
   751
    MethodEmitter loadConstants() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   752
        getStatic(classEmitter.getUnitClassName(), CONSTANTS.symbolName(), CONSTANTS.descriptor());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   753
        assert peekType().isArray() : peekType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   754
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   755
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   756
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   757
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   758
     * Push the undefined value for the given type, i.e.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   759
     * UNDEFINED or UNDEFINEDNUMBER. Currently we have no way of
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   760
     * representing UNDEFINED for INTs and LONGs, so they are not
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   761
     * allowed to be local variables (yet)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   762
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   763
     * @param type the type for which to push UNDEFINED
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   764
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   765
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   766
    MethodEmitter loadUndefined(final Type type) {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
   767
        debug("load undefined ", type);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   768
        pushType(type.loadUndefined(method));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   769
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   770
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   771
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   772
    MethodEmitter loadForcedInitializer(final Type type) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   773
        debug("load forced initializer ", type);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   774
        pushType(type.loadForcedInitializer(method));
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   775
        return this;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   776
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   777
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   778
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   779
     * Push the empty value for the given type, i.e. EMPTY.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   780
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   781
     * @param type the type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   782
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   783
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   784
    MethodEmitter loadEmpty(final Type type) {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
   785
        debug("load empty ", type);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   786
        pushType(type.loadEmpty(method));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   787
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   788
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   789
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   790
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   791
     * Push null to stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   792
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   793
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   794
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   795
    MethodEmitter loadNull() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   796
        debug("aconst_null");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   797
        pushType(Type.OBJECT.ldc(method, null));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   798
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   799
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   800
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   801
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   802
     * Push a handle representing this class top stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   803
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   804
     * @param className name of the class
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   805
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   806
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   807
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   808
    MethodEmitter loadType(final String className) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   809
        debug("load type", className);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   810
        method.visitLdcInsn(jdk.internal.org.objectweb.asm.Type.getObjectType(className));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   811
        pushType(Type.OBJECT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   812
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   813
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   814
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   815
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   816
     * Push a boolean constant to the stack.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   817
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   818
     * @param b value of boolean
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   819
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   820
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   821
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   822
    MethodEmitter load(final boolean b) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   823
        debug("load boolean", b);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   824
        pushType(Type.BOOLEAN.ldc(method, b));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   825
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   826
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   827
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   828
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   829
     * Push an int constant to the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   830
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   831
     * @param i value of the int
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   832
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   833
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   834
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   835
    MethodEmitter load(final int i) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   836
        debug("load int", i);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   837
        pushType(Type.INT.ldc(method, i));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   838
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   839
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   840
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   841
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   842
     * Push a double constant to the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   843
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   844
     * @param d value of the double
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   845
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   846
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   847
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   848
    MethodEmitter load(final double d) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   849
        debug("load double", d);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   850
        pushType(Type.NUMBER.ldc(method, d));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   851
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   852
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   853
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   854
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   855
     * Push an long constant to the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   856
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   857
     * @param l value of the long
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   858
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   859
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   860
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   861
    MethodEmitter load(final long l) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   862
        debug("load long", l);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   863
        pushType(Type.LONG.ldc(method, l));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   864
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   865
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   866
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   867
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   868
     * Fetch the length of an array.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   869
     * @return Array length.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   870
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   871
    MethodEmitter arraylength() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   872
        debug("arraylength");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   873
        popType(Type.OBJECT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   874
        pushType(Type.OBJECT_ARRAY.arraylength(method));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   875
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   876
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   877
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   878
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   879
     * Push a String constant to the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   880
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   881
     * @param s value of the String
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   882
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   883
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   884
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   885
    MethodEmitter load(final String s) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   886
        debug("load string", s);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   887
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   888
        if (s == null) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   889
            loadNull();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   890
            return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   891
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   892
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   893
        //NASHORN-142 - split too large string
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   894
        final int length = s.length();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   895
        if (length > LARGE_STRING_THRESHOLD) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   896
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   897
            _new(StringBuilder.class);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   898
            dup();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   899
            load(length);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   900
            invoke(constructorNoLookup(StringBuilder.class, int.class));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   901
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   902
            for (int n = 0; n < length; n += LARGE_STRING_THRESHOLD) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   903
                final String part = s.substring(n, Math.min(n + LARGE_STRING_THRESHOLD, length));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   904
                load(part);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   905
                stringBuilderAppend();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   906
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   907
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   908
            invoke(virtualCallNoLookup(StringBuilder.class, "toString", String.class));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   909
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   910
            return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   911
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   912
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   913
        pushType(Type.OBJECT.ldc(method, s));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   914
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   915
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   916
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   917
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   918
     * Pushes the value of an identifier to the stack. If the identifier does not represent a local variable or a
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   919
     * parameter, this will be a no-op.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   920
     *
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   921
     * @param ident the identifier for the variable being loaded.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   922
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   923
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   924
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   925
    MethodEmitter load(final IdentNode ident) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   926
        return load(ident.getSymbol(), ident.getType());
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   927
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   928
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   929
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   930
     * Pushes the value of the symbol to the stack with the specified type. No type conversion is being performed, and
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   931
     * the type is only being used if the symbol addresses a local variable slot. The value of the symbol is loaded if
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   932
     * it addresses a local variable slot, or it is a parameter (in which case it can also be loaded from a vararg array
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   933
     * or the arguments object). If it is neither, the operation is a no-op.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   934
     *
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   935
     * @param symbol the symbol addressing the value being loaded
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   936
     * @param type the presumed type of the value when it is loaded from a local variable slot
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   937
     * @return the method emitter
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   938
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   939
    MethodEmitter load(final Symbol symbol, final Type type) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   940
        assert symbol != null;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   941
        if (symbol.hasSlot()) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   942
            final int slot = symbol.getSlot(type);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   943
            debug("load symbol", symbol.getName(), " slot=", slot, "type=", type);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   944
            load(type, slot);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   945
           // _try(new Label("dummy"), new Label("dummy2"), recovery);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   946
           // method.visitTryCatchBlock(new Label(), arg1, arg2, arg3);
16209
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
   947
        } else if (symbol.isParam()) {
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
   948
            assert functionNode.isVarArg() : "Non-vararg functions have slotted parameters";
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
   949
            final int index = symbol.getFieldIndex();
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   950
            if (functionNode.needsArguments()) {
16209
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
   951
                // ScriptObject.getArgument(int) on arguments
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
   952
                debug("load symbol", symbol.getName(), " arguments index=", index);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   953
                loadCompilerConstant(ARGUMENTS);
16209
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
   954
                load(index);
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
   955
                ScriptObject.GET_ARGUMENT.invoke(this);
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
   956
            } else {
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
   957
                // array load from __varargs__
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
   958
                debug("load symbol", symbol.getName(), " array index=", index);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   959
                loadCompilerConstant(VARARGS);
16209
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
   960
                load(symbol.getFieldIndex());
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
   961
                arrayload();
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
   962
            }
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   963
        }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   964
        return this;
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   965
    }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   966
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   967
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   968
     * Push a local variable to the stack, given an explicit bytecode slot.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   969
     * This is used e.g. for stub generation where we know where items like
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   970
     * "this" and "scope" reside.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   971
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   972
     * @param type  the type of the variable
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   973
     * @param slot  the slot the variable is in
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   974
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   975
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   976
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   977
    MethodEmitter load(final Type type, final int slot) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   978
        debug("explicit load", type, slot);
16225
81d58c2b9fcf 8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents: 16210
diff changeset
   979
        final Type loadType = type.load(method, slot);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   980
        assert loadType != null;
16225
81d58c2b9fcf 8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents: 16210
diff changeset
   981
        pushType(loadType == Type.OBJECT && isThisSlot(slot) ? Type.THIS : loadType);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   982
        assert !preventUndefinedLoad || (slot < stack.localVariableTypes.size() && stack.localVariableTypes.get(slot) != Type.UNKNOWN)
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   983
            : "Attempted load of uninitialized slot " + slot + " (as type " + type + ")";
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
   984
        stack.markLocalLoad(slot);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   985
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   986
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   987
16225
81d58c2b9fcf 8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents: 16210
diff changeset
   988
    private boolean isThisSlot(final int slot) {
17527
6e45d9c2328c 8014329: Slim down the label stack structure in CodeGenerator
lagergren
parents: 17524
diff changeset
   989
        if (functionNode == null) {
16225
81d58c2b9fcf 8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents: 16210
diff changeset
   990
            return slot == CompilerConstants.JAVA_THIS.slot();
81d58c2b9fcf 8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents: 16210
diff changeset
   991
        }
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
   992
        final int thisSlot = getCompilerConstantSymbol(THIS).getSlot(Type.OBJECT);
16225
81d58c2b9fcf 8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents: 16210
diff changeset
   993
        assert !functionNode.needsCallee() || thisSlot == 1; // needsCallee -> thisSlot == 1
81d58c2b9fcf 8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents: 16210
diff changeset
   994
        assert functionNode.needsCallee() || thisSlot == 0; // !needsCallee -> thisSlot == 0
81d58c2b9fcf 8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents: 16210
diff changeset
   995
        return slot == thisSlot;
81d58c2b9fcf 8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents: 16210
diff changeset
   996
    }
81d58c2b9fcf 8006943: Fix order of function method arguments to be (callee, thisObject)
attila
parents: 16210
diff changeset
   997
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   998
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   999
     * Push a method handle to the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1000
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1001
     * @param className  class name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1002
     * @param methodName method name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1003
     * @param descName   descriptor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1004
     * @param flags      flags that describe this handle, e.g. invokespecial new, or invoke virtual
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1005
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1006
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1007
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1008
    MethodEmitter loadHandle(final String className, final String methodName, final String descName, final EnumSet<Flag> flags) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1009
        debug("load handle ");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1010
        pushType(Type.OBJECT.ldc(method, new Handle(Flag.getValue(flags), className, methodName, descName)));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1011
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1012
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1013
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1014
    private Symbol getCompilerConstantSymbol(final CompilerConstants cc) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1015
        return functionNode.getBody().getExistingSymbol(cc.symbolName());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1016
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1017
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17246
diff changeset
  1018
    /**
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17246
diff changeset
  1019
     * True if this method has a slot allocated for the scope variable (meaning, something in the method actually needs
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17246
diff changeset
  1020
     * the scope).
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17246
diff changeset
  1021
     * @return if this method has a slot allocated for the scope variable.
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17246
diff changeset
  1022
     */
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17246
diff changeset
  1023
    boolean hasScope() {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1024
        return getCompilerConstantSymbol(SCOPE).hasSlot();
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17246
diff changeset
  1025
    }
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17246
diff changeset
  1026
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1027
    MethodEmitter loadCompilerConstant(final CompilerConstants cc) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1028
        return loadCompilerConstant(cc, null);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1029
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1030
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1031
    MethodEmitter loadCompilerConstant(final CompilerConstants cc, final Type type) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1032
        if (cc == SCOPE && peekType() == Type.SCOPE) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1033
            dup();
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1034
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1035
        }
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1036
        return load(getCompilerConstantSymbol(cc), type != null ? type : getCompilerConstantType(cc));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1037
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1038
26890
fa03d7a7d50e 8059372: Code duplication in split emitter
attila
parents: 26887
diff changeset
  1039
    MethodEmitter loadScope() {
fa03d7a7d50e 8059372: Code duplication in split emitter
attila
parents: 26887
diff changeset
  1040
        return loadCompilerConstant(SCOPE).checkcast(Scope.class);
fa03d7a7d50e 8059372: Code duplication in split emitter
attila
parents: 26887
diff changeset
  1041
    }
fa03d7a7d50e 8059372: Code duplication in split emitter
attila
parents: 26887
diff changeset
  1042
fa03d7a7d50e 8059372: Code duplication in split emitter
attila
parents: 26887
diff changeset
  1043
    MethodEmitter setSplitState(final int state) {
fa03d7a7d50e 8059372: Code duplication in split emitter
attila
parents: 26887
diff changeset
  1044
        return loadScope().load(state).invoke(Scope.SET_SPLIT_STATE);
fa03d7a7d50e 8059372: Code duplication in split emitter
attila
parents: 26887
diff changeset
  1045
    }
fa03d7a7d50e 8059372: Code duplication in split emitter
attila
parents: 26887
diff changeset
  1046
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1047
    void storeCompilerConstant(final CompilerConstants cc) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1048
        storeCompilerConstant(cc, null);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1049
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1050
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1051
    void storeCompilerConstant(final CompilerConstants cc, final Type type) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1052
        final Symbol symbol = getCompilerConstantSymbol(cc);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1053
        if(!symbol.hasSlot()) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1054
            return;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1055
        }
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1056
        debug("store compiler constant ", symbol);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1057
        store(symbol, type != null ? type : getCompilerConstantType(cc));
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1058
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1059
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1060
    private static Type getCompilerConstantType(final CompilerConstants cc) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1061
        final Class<?> constantType = cc.type();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1062
        assert constantType != null;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1063
        return Type.typeFor(constantType);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1064
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1065
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1066
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1067
     * Load an element from an array, determining type automatically
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1068
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1069
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1070
    MethodEmitter arrayload() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1071
        debug("Xaload");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1072
        popType(Type.INT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1073
        pushType(popArray().aload(method));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1074
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1075
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1076
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1077
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1078
     * Pop a value, an index and an array from the stack and store
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1079
     * the value at the given index in the array.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1080
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1081
    void arraystore() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1082
        debug("Xastore");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1083
        final Type value = popType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1084
        final Type index = popType(Type.INT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1085
        assert index.isInteger() : "array index is not integer, but " + index;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1086
        final ArrayType array = popArray();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1087
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1088
        assert value.isEquivalentTo(array.getElementType()) : "Storing "+value+" into "+array;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1089
        assert array.isObject();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1090
        array.astore(method);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1091
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1092
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1093
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1094
     * Pop a value from the stack and store it in a local variable represented
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1095
     * by the given identifier. If the symbol has no slot, this is a NOP
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1096
     *
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1097
     * @param ident identifier to store stack to
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1098
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1099
    void store(final IdentNode ident) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1100
        final Type type = ident.getType();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1101
        final Symbol symbol = ident.getSymbol();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1102
        if(type == Type.UNDEFINED) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1103
            assert peekType() == Type.UNDEFINED;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1104
            store(symbol, Type.OBJECT);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1105
        } else {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1106
            store(symbol, type);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1107
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1108
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1109
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1110
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1111
     * Represents a definition of a local variable with a type. Used for local variable table building.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1112
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1113
    private static class LocalVariableDef {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1114
        // The start label from where this definition lives.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1115
        private final jdk.internal.org.objectweb.asm.Label label;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1116
        // The currently live type of the local variable.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1117
        private final Type type;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1118
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1119
        LocalVariableDef(final jdk.internal.org.objectweb.asm.Label label, final Type type) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1120
            this.label = label;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1121
            this.type = type;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1122
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1123
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1124
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1125
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1126
    void closeLocalVariable(final Symbol symbol, final Label label) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1127
        final LocalVariableDef def = localVariableDefs.get(symbol);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1128
        if(def != null) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1129
            endLocalValueDef(symbol, def, label.getLabel());
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1130
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1131
        if(isReachable()) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1132
            markDeadLocalVariable(symbol);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1133
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1134
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1135
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1136
    void markDeadLocalVariable(final Symbol symbol) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1137
        if(!symbol.isDead()) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1138
            markDeadSlots(symbol.getFirstSlot(), symbol.slotCount());
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1139
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1140
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1141
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1142
    void markDeadSlots(final int firstSlot, final int slotCount) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1143
        stack.markDeadLocalVariables(firstSlot, slotCount);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1144
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1145
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1146
    private void endLocalValueDef(final Symbol symbol, final LocalVariableDef def, final jdk.internal.org.objectweb.asm.Label label) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1147
        String name = symbol.getName();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1148
        if (name.equals(THIS.symbolName())) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1149
            name = THIS_DEBUGGER.symbolName();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1150
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1151
        method.visitLocalVariable(name, def.type.getDescriptor(), null, def.label, label, symbol.getSlot(def.type));
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1152
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1153
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1154
    void store(final Symbol symbol, final Type type) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1155
        store(symbol, type, true);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1156
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1157
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1158
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1159
     * Pop a value from the stack and store it in a variable denoted by the given symbol. The variable should be either
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1160
     * a local variable, or a function parameter (and not a scoped variable). For local variables, this method will also
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1161
     * do the bookeeping of the local variable table as well as mark values in all alternative slots for the symbol as
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1162
     * dead. In this regard it differs from {@link #storeHidden(Type, int)}.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1163
     *
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1164
     * @param symbol the symbol to store into.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1165
     * @param type the type to store
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1166
     * @param onlySymbolLiveValue if true, this is the sole live value for the symbol. If false, currently live values should
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1167
     * be kept live.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1168
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1169
    void store(final Symbol symbol, final Type type, final boolean onlySymbolLiveValue) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16154
diff changeset
  1170
        assert symbol != null : "No symbol to store";
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1171
        if (symbol.hasSlot()) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1172
            final boolean isLiveType = symbol.hasSlotFor(type);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1173
            final LocalVariableDef existingDef = localVariableDefs.get(symbol);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1174
            if(existingDef == null || existingDef.type != type) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1175
                final jdk.internal.org.objectweb.asm.Label here = new jdk.internal.org.objectweb.asm.Label();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1176
                if(isLiveType) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1177
                    final LocalVariableDef newDef = new LocalVariableDef(here, type);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1178
                    localVariableDefs.put(symbol, newDef);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1179
                }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1180
                method.visitLabel(here);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1181
                if(existingDef != null) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1182
                    endLocalValueDef(symbol, existingDef, here);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1183
                }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1184
            }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1185
            if(isLiveType) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1186
                final int slot = symbol.getSlot(type);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1187
                debug("store symbol", symbol.getName(), " type=", type, " slot=", slot);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1188
                storeHidden(type, slot, onlySymbolLiveValue);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1189
            } else {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1190
                if(onlySymbolLiveValue) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1191
                    markDeadLocalVariable(symbol);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1192
                }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1193
                debug("dead store symbol ", symbol.getName(), " type=", type);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1194
                pop();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1195
            }
16209
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
  1196
        } else if (symbol.isParam()) {
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
  1197
            assert !symbol.isScope();
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
  1198
            assert functionNode.isVarArg() : "Non-vararg functions have slotted parameters";
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
  1199
            final int index = symbol.getFieldIndex();
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1200
            if (functionNode.needsArguments()) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1201
                convert(Type.OBJECT);
16209
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
  1202
                debug("store symbol", symbol.getName(), " arguments index=", index);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1203
                loadCompilerConstant(ARGUMENTS);
16209
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
  1204
                load(index);
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
  1205
                ArgumentSetter.SET_ARGUMENT.invoke(this);
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
  1206
            } else {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1207
                convert(Type.OBJECT);
16209
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
  1208
                // varargs without arguments object - just do array store to __varargs__
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
  1209
                debug("store symbol", symbol.getName(), " array index=", index);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1210
                loadCompilerConstant(VARARGS);
16209
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
  1211
                load(index);
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
  1212
                ArgumentSetter.SET_ARRAY_ELEMENT.invoke(this);
18e55b352d56 8007460: var assignment to a parameter in a varargs method causes compilation error
attila
parents: 16206
diff changeset
  1213
            }
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1214
        } else {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1215
            debug("dead store symbol ", symbol.getName(), " type=", type);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1216
            pop();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1217
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1218
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1219
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1220
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1221
     * Pop a value from the stack and store it in a local variable slot. Note that in contrast with
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1222
     * {@link #store(Symbol, Type)}, this method does not adjust the local variable table, nor marks slots for
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1223
     * alternative value types for the symbol as being dead. For that reason, this method is usually not called
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1224
     * directly. Notable exceptions are temporary internal locals (e.g. quick store, last-catch-condition, etc.) that
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1225
     * are not desired to show up in the local variable table.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1226
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1227
     * @param type the type to pop
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1228
     * @param slot the slot
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1229
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1230
    void storeHidden(final Type type, final int slot) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1231
        storeHidden(type, slot, true);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1232
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1233
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1234
    void storeHidden(final Type type, final int slot, final boolean onlyLiveSymbolValue) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1235
        explicitStore(type, slot);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1236
        stack.onLocalStore(type, slot, onlyLiveSymbolValue);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1237
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1238
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1239
    void storeTemp(final Type type, final int slot) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1240
        explicitStore(type, slot);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1241
        defineTemporaryLocalVariable(slot, slot + type.getSlots());
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1242
        onLocalStore(type, slot);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1243
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1244
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1245
    void onLocalStore(final Type type, final int slot) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1246
        stack.onLocalStore(type, slot, true);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1247
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1248
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1249
    private void explicitStore(final Type type, final int slot) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1250
        assert slot != -1;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1251
        debug("explicit store", type, slot);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1252
        popType(type);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1253
        type.store(method, slot);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1254
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1255
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1256
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1257
     * Marks a range of slots as belonging to a defined local variable. The slots will start out with no live value
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1258
     * in them.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1259
     * @param fromSlot first slot, inclusive.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1260
     * @param toSlot last slot, exclusive.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1261
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1262
    void defineBlockLocalVariable(final int fromSlot, final int toSlot) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1263
        stack.defineBlockLocalVariable(fromSlot, toSlot);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1264
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1265
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1266
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1267
     * Marks a range of slots as belonging to a defined temporary local variable. The slots will start out with no
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1268
     * live value in them.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1269
     * @param fromSlot first slot, inclusive.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1270
     * @param toSlot last slot, exclusive.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1271
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1272
    void defineTemporaryLocalVariable(final int fromSlot, final int toSlot) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1273
        stack.defineTemporaryLocalVariable(fromSlot, toSlot);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1274
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1275
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1276
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1277
     * Defines a new temporary local variable and returns its allocated index.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1278
     * @param width the required width (in slots) for the new variable.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1279
     * @return the bytecode slot index where the newly allocated local begins.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1280
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1281
    int defineTemporaryLocalVariable(final int width) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1282
        return stack.defineTemporaryLocalVariable(width);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1283
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1284
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1285
    void undefineLocalVariables(final int fromSlot, final boolean canTruncateSymbol) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1286
        if(isReachable()) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1287
            stack.undefineLocalVariables(fromSlot, canTruncateSymbol);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1288
        }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1289
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1290
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1291
    List<Type> getLocalVariableTypes() {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1292
        return stack.localVariableTypes;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1293
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1294
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1295
    List<Type> getWidestLiveLocals(final List<Type> localTypes) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1296
        return stack.getWidestLiveLocals(localTypes);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1297
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1298
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1299
    String markSymbolBoundariesInLvarTypesDescriptor(final String lvarDescriptor) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1300
        return stack.markSymbolBoundariesInLvarTypesDescriptor(lvarDescriptor);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1301
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1302
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1303
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1304
     * Increment/Decrement a local integer by the given value.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1305
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1306
     * @param slot the int slot
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1307
     * @param increment the amount to increment
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1308
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1309
    void iinc(final int slot, final int increment) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1310
        debug("iinc");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1311
        method.visitIincInsn(slot, increment);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1312
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1313
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1314
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1315
     * Pop an exception object from the stack and generate code
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1316
     * for throwing it
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1317
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1318
    public void athrow() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1319
        debug("athrow");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1320
        final Type receiver = popType(Type.OBJECT);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1321
        assert Throwable.class.isAssignableFrom(receiver.getTypeClass()) : receiver.getTypeClass();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1322
        method.visitInsn(ATHROW);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1323
        doesNotContinueSequentially();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1324
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1325
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1326
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1327
     * Pop an object from the stack and perform an instanceof
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1328
     * operation, given a classDescriptor to compare it to.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1329
     * Push the boolean result 1/0 as an int to the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1330
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1331
     * @param classDescriptor descriptor of the class to type check against
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1332
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1333
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1334
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1335
    MethodEmitter _instanceof(final String classDescriptor) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1336
        debug("instanceof", classDescriptor);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1337
        popType(Type.OBJECT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1338
        method.visitTypeInsn(INSTANCEOF, classDescriptor);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1339
        pushType(Type.INT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1340
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1341
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1342
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1343
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1344
     * Pop an object from the stack and perform an instanceof
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1345
     * operation, given a classDescriptor to compare it to.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1346
     * Push the boolean result 1/0 as an int to the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1347
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1348
     * @param clazz the type to check instanceof against
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1349
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1350
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1351
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1352
    MethodEmitter _instanceof(final Class<?> clazz) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1353
        return _instanceof(CompilerConstants.className(clazz));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1354
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1355
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1356
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1357
     * Perform a checkcast operation on the object at the top of the
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1358
     * stack.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1359
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1360
     * @param classDescriptor descriptor of the class to type check against
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1361
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1362
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1363
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1364
    MethodEmitter checkcast(final String classDescriptor) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1365
        debug("checkcast", classDescriptor);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1366
        assert peekType().isObject();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1367
        method.visitTypeInsn(CHECKCAST, classDescriptor);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1368
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1369
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1370
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1371
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1372
     * Perform a checkcast operation on the object at the top of the
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1373
     * stack.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1374
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1375
     * @param clazz class to checkcast against
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1376
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1377
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1378
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1379
    MethodEmitter checkcast(final Class<?> clazz) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1380
        return checkcast(CompilerConstants.className(clazz));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1381
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1382
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1383
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1384
     * Instantiate a new array given a length that is popped
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1385
     * from the stack and the array type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1386
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1387
     * @param arrayType the type of the array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1388
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1389
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1390
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1391
    MethodEmitter newarray(final ArrayType arrayType) {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
  1392
        debug("newarray ", "arrayType=", arrayType);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1393
        popType(Type.INT); //LENGTH
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1394
        pushType(arrayType.newarray(method));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1395
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1396
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1397
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1398
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1399
     * Instantiate a multidimensional array with a given number of dimensions.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1400
     * On the stack are dim lengths of the sub arrays.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1401
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1402
     * @param arrayType type of the array
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1403
     * @param dims      number of dimensions
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1404
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1405
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1406
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1407
    MethodEmitter multinewarray(final ArrayType arrayType, final int dims) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1408
        debug("multianewarray ", arrayType, dims);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1409
        for (int i = 0; i < dims; i++) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1410
            popType(Type.INT); //LENGTH
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1411
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1412
        pushType(arrayType.newarray(method, dims));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1413
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1414
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1415
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1416
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1417
     * Helper function to pop and type check the appropriate arguments
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1418
     * from the stack given a method signature
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1419
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1420
     * @param signature method signature
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1421
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1422
     * @return return type of method
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1423
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1424
    private Type fixParamStack(final String signature) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1425
        final Type[] params = Type.getMethodArguments(signature);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1426
        for (int i = params.length - 1; i >= 0; i--) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1427
            popType(params[i]);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1428
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1429
        final Type returnType = Type.getMethodReturnType(signature);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1430
        return returnType;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1431
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1432
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1433
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1434
     * Generate an invocation to a Call structure
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1435
     * @see CompilerConstants
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1436
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1437
     * @param call the call object
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1438
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1439
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1440
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1441
    MethodEmitter invoke(final Call call) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1442
        return call.invoke(this);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1443
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1444
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1445
    private MethodEmitter invoke(final int opcode, final String className, final String methodName, final String methodDescriptor, final boolean hasReceiver) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1446
        final Type returnType = fixParamStack(methodDescriptor);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1447
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1448
        if (hasReceiver) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1449
            popType(Type.OBJECT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1450
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1451
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1452
        method.visitMethodInsn(opcode, className, methodName, methodDescriptor, opcode == INVOKEINTERFACE);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1453
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1454
        if (returnType != null) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1455
            pushType(returnType);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1456
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1457
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1458
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1459
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1460
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1461
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1462
     * Pop receiver from stack, perform an invoke special
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1463
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1464
     * @param className        class name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1465
     * @param methodName       method name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1466
     * @param methodDescriptor descriptor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1467
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1468
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1469
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1470
    MethodEmitter invokespecial(final String className, final String methodName, final String methodDescriptor) {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
  1471
        debug("invokespecial", className, ".", methodName, methodDescriptor);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1472
        return invoke(INVOKESPECIAL, className, methodName, methodDescriptor, true);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1473
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1474
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1475
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1476
     * Pop receiver from stack, perform an invoke virtual, push return value if any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1477
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1478
     * @param className        class name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1479
     * @param methodName       method name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1480
     * @param methodDescriptor descriptor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1481
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1482
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1483
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1484
    MethodEmitter invokevirtual(final String className, final String methodName, final String methodDescriptor) {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
  1485
        debug("invokevirtual", className, ".", methodName, methodDescriptor, " ", stack);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1486
        return invoke(INVOKEVIRTUAL, className, methodName, methodDescriptor, true);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1487
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1488
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1489
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1490
     * Perform an invoke static and push the return value if any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1491
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1492
     * @param className        class name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1493
     * @param methodName       method name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1494
     * @param methodDescriptor descriptor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1495
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1496
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1497
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1498
    MethodEmitter invokestatic(final String className, final String methodName, final String methodDescriptor) {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
  1499
        debug("invokestatic", className, ".", methodName, methodDescriptor);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1500
        invoke(INVOKESTATIC, className, methodName, methodDescriptor, false);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1501
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1502
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1503
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1504
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1505
     * Perform an invoke static and replace the return type if we know better, e.g. Global.allocate
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1506
     * that allocates an array should return an ObjectArray type as a NativeArray counts as that
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1507
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1508
     * @param className        class name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1509
     * @param methodName       method name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1510
     * @param methodDescriptor descriptor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1511
     * @param returnType       return type override
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1512
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1513
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1514
     */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1515
    MethodEmitter invokestatic(final String className, final String methodName, final String methodDescriptor, final Type returnType) {
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1516
        invokestatic(className, methodName, methodDescriptor);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1517
        popType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1518
        pushType(returnType);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1519
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1520
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1521
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1522
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1523
     * Pop receiver from stack, perform an invoke interface and push return value if any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1524
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1525
     * @param className        class name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1526
     * @param methodName       method name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1527
     * @param methodDescriptor descriptor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1528
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1529
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1530
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1531
    MethodEmitter invokeinterface(final String className, final String methodName, final String methodDescriptor) {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
  1532
        debug("invokeinterface", className, ".", methodName, methodDescriptor);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1533
        return invoke(INVOKEINTERFACE, className, methodName, methodDescriptor, true);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1534
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1535
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1536
    static jdk.internal.org.objectweb.asm.Label[] getLabels(final Label... table) {
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1537
        final jdk.internal.org.objectweb.asm.Label[] internalLabels = new jdk.internal.org.objectweb.asm.Label[table.length];
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1538
        for (int i = 0; i < table.length; i++) {
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1539
            internalLabels[i] = table[i].getLabel();
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1540
        }
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1541
        return internalLabels;
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1542
    }
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1543
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1544
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1545
     * Generate a lookup switch, popping the switch value from the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1546
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1547
     * @param defaultLabel default label
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1548
     * @param values       case values for the table
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1549
     * @param table        default label
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1550
     */
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1551
    void lookupswitch(final Label defaultLabel, final int[] values, final Label... table) {//Collection<Label> table) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1552
        debug("lookupswitch", peekType());
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1553
        adjustStackForSwitch(defaultLabel, table);
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1554
        method.visitLookupSwitchInsn(defaultLabel.getLabel(), values, getLabels(table));
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1555
        doesNotContinueSequentially();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1556
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1557
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1558
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1559
     * Generate a table switch
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1560
     * @param lo            low value
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1561
     * @param hi            high value
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1562
     * @param defaultLabel  default label
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1563
     * @param table         label table
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1564
     */
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1565
    void tableswitch(final int lo, final int hi, final Label defaultLabel, final Label... table) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1566
        debug("tableswitch", peekType());
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1567
        adjustStackForSwitch(defaultLabel, table);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1568
        method.visitTableSwitchInsn(lo, hi, defaultLabel.getLabel(), getLabels(table));
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1569
        doesNotContinueSequentially();
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1570
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1571
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1572
    private void adjustStackForSwitch(final Label defaultLabel, final Label... table) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1573
        popType(Type.INT);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1574
        joinTo(defaultLabel);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1575
        for(final Label label: table) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1576
            joinTo(label);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1577
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1578
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1579
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1580
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1581
     * Abstraction for performing a conditional jump of any type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1582
     *
27368
939ac7c411bc 8047365: Very long function names break codegen
hannesw
parents: 27206
diff changeset
  1583
     * @see Condition
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1584
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1585
     * @param cond      the condition to test
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1586
     * @param trueLabel the destination label is condition is true
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1587
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1588
    void conditionalJump(final Condition cond, final Label trueLabel) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1589
        conditionalJump(cond, cond != Condition.GT && cond != Condition.GE, trueLabel);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1590
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1591
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1592
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1593
     * Abstraction for performing a conditional jump of any type,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1594
     * including a dcmpg/dcmpl semantic for doubles.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1595
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1596
     * @param cond      the condition to test
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1597
     * @param isCmpG    is this a dcmpg for numbers, false if it's a dcmpl
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1598
     * @param trueLabel the destination label if condition is true
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1599
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1600
    void conditionalJump(final Condition cond, final boolean isCmpG, final Label trueLabel) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1601
        if (peekType().isCategory2()) {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
  1602
            debug("[ld]cmp isCmpG=", isCmpG);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1603
            pushType(get2n().cmp(method, isCmpG));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1604
            jump(Condition.toUnary(cond), trueLabel, 1);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1605
        } else {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
  1606
            debug("if", cond);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1607
            jump(Condition.toBinary(cond, peekType().isObject()), trueLabel, 2);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1608
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1609
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1610
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1611
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1612
     * Perform a non void return, popping the type from the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1613
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1614
     * @param type the type for the return
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1615
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1616
    void _return(final Type type) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1617
        debug("return", type);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1618
        assert stack.size() == 1 : "Only return value on stack allowed at return point - depth=" + stack.size() + " stack = " + stack;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1619
        final Type stackType = peekType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1620
        if (!Type.areEquivalent(type, stackType)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1621
            convert(type);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1622
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1623
        popType(type)._return(method);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1624
        doesNotContinueSequentially();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1625
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1626
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1627
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1628
     * Perform a return using the stack top value as the guide for the type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1629
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1630
    void _return() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1631
        _return(peekType());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1632
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1633
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1634
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1635
     * Perform a void return.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1636
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1637
    void returnVoid() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1638
        debug("return [void]");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1639
        assert stack.isEmpty() : stack;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1640
        method.visitInsn(RETURN);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1641
        doesNotContinueSequentially();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1642
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1643
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1644
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1645
     * Perform a comparison of two number types that are popped from the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1646
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1647
     * @param isCmpG is this a dcmpg semantic, false if it's a dcmpl semantic
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1648
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1649
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1650
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1651
    MethodEmitter cmp(final boolean isCmpG) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1652
        pushType(get2n().cmp(method, isCmpG));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1653
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1654
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1655
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1656
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1657
     * Helper function for jumps, conditional or not
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1658
     * @param opcode  opcode for jump
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1659
     * @param label   destination
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1660
     * @param n       elements on stack to compare, 0-2
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1661
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1662
    private void jump(final int opcode, final Label label, final int n) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1663
        for (int i = 0; i < n; i++) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1664
            assert peekType().isInteger() || peekType().isBoolean() || peekType().isObject() : "expecting integer type or object for jump, but found " + peekType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1665
            popType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1666
        }
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1667
        joinTo(label);
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1668
        method.visitJumpInsn(opcode, label.getLabel());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1669
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1670
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1671
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1672
     * Generate an if_acmpeq
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1673
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1674
     * @param label label to true case
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1675
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1676
    void if_acmpeq(final Label label) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1677
        debug("if_acmpeq", label);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1678
        jump(IF_ACMPEQ, label, 2);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1679
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1680
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1681
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1682
     * Generate an if_acmpne
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1683
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1684
     * @param label label to true case
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1685
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1686
    void if_acmpne(final Label label) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1687
        debug("if_acmpne", label);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1688
        jump(IF_ACMPNE, label, 2);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1689
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1690
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1691
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1692
     * Generate an ifnull
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1693
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1694
     * @param label label to true case
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1695
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1696
    void ifnull(final Label label) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1697
        debug("ifnull", label);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1698
        jump(IFNULL, label, 1);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1699
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1700
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1701
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1702
     * Generate an ifnonnull
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1703
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1704
     * @param label label to true case
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1705
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1706
    void ifnonnull(final Label label) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1707
        debug("ifnonnull", label);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1708
        jump(IFNONNULL, label, 1);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1709
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1710
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1711
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1712
     * Generate an ifeq
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1713
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1714
     * @param label label to true case
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1715
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1716
    void ifeq(final Label label) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1717
        debug("ifeq ", label);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1718
        jump(IFEQ, label, 1);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1719
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1720
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1721
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1722
     * Generate an if_icmpeq
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1723
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1724
     * @param label label to true case
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1725
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1726
    void if_icmpeq(final Label label) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1727
        debug("if_icmpeq", label);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1728
        jump(IF_ICMPEQ, label, 2);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1729
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1730
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1731
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1732
     * Generate an if_ne
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1733
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1734
     * @param label label to true case
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1735
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1736
    void ifne(final Label label) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1737
        debug("ifne", label);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1738
        jump(IFNE, label, 1);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1739
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1740
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1741
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1742
     * Generate an if_icmpne
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1743
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1744
     * @param label label to true case
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1745
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1746
    void if_icmpne(final Label label) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1747
        debug("if_icmpne", label);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1748
        jump(IF_ICMPNE, label, 2);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1749
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1750
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1751
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1752
     * Generate an iflt
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1753
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1754
     * @param label label to true case
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1755
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1756
    void iflt(final Label label) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1757
        debug("iflt", label);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1758
        jump(IFLT, label, 1);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1759
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1760
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1761
    /**
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1762
     * Generate an if_icmplt
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1763
     *
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1764
     * @param label label to true case
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1765
     */
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1766
    void if_icmplt(final Label label) {
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1767
        debug("if_icmplt", label);
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1768
        jump(IF_ICMPLT, label, 2);
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1769
    }
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1770
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1771
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1772
     * Generate an ifle
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1773
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1774
     * @param label label to true case
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1775
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1776
    void ifle(final Label label) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1777
        debug("ifle", label);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1778
        jump(IFLE, label, 1);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1779
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1780
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1781
    /**
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1782
     * Generate an if_icmple
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1783
     *
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1784
     * @param label label to true case
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1785
     */
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1786
    void if_icmple(final Label label) {
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1787
        debug("if_icmple", label);
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1788
        jump(IF_ICMPLE, label, 2);
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1789
    }
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1790
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1791
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1792
     * Generate an ifgt
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1793
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1794
     * @param label label to true case
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1795
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1796
    void ifgt(final Label label) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1797
        debug("ifgt", label);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1798
        jump(IFGT, label, 1);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1799
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1800
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1801
    /**
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1802
     * Generate an if_icmpgt
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1803
     *
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1804
     * @param label label to true case
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1805
     */
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1806
    void if_icmpgt(final Label label) {
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1807
        debug("if_icmpgt", label);
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1808
        jump(IF_ICMPGT, label, 2);
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1809
    }
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1810
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1811
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1812
     * Generate an ifge
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1813
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1814
     * @param label label to true case
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1815
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1816
    void ifge(final Label label) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1817
        debug("ifge", label);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1818
        jump(IFGE, label, 1);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1819
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1820
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1821
    /**
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1822
     * Generate an if_icmpge
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1823
     *
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1824
     * @param label label to true case
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1825
     */
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1826
    void if_icmpge(final Label label) {
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1827
        debug("if_icmpge", label);
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1828
        jump(IF_ICMPGE, label, 2);
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1829
    }
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1830
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  1831
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1832
     * Unconditional jump to a label
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1833
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1834
     * @param label destination label
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1835
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1836
    void _goto(final Label label) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1837
        debug("goto", label);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1838
        jump(GOTO, label, 0);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1839
        doesNotContinueSequentially(); //whoever reaches the point after us provides the stack, because we don't
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1840
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1841
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1842
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1843
     * Unconditional jump to the start label of a loop. It differs from ordinary {@link #_goto(Label)} in that it will
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1844
     * preserve the current label stack, as the next instruction after the goto is loop body that the loop will come
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1845
     * back to. Also used to jump at the start label of the continuation handler, as it behaves much like a loop test in
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1846
     * the sense that after it is evaluated, it also jumps backwards.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1847
     *
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1848
     * @param loopStart start label of a loop
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1849
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1850
    void gotoLoopStart(final Label loopStart) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1851
        debug("goto (loop)", loopStart);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1852
        jump(GOTO, loopStart, 0);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1853
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1854
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1855
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1856
     * Unconditional jump without any control flow and data flow testing. You should not normally use this method when
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1857
     * generating code, except if you're very sure that you know what you're doing. Normally only used for the
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1858
     * admittedly torturous control flow of continuation handler plumbing.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1859
     * @param target the target of the jump
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1860
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1861
    void uncheckedGoto(final Label target) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1862
        method.visitJumpInsn(GOTO, target.getLabel());
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1863
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1864
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1865
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1866
     * Potential transfer of control to a catch block.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1867
     *
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1868
     * @param catchLabel destination catch label
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1869
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1870
    void canThrow(final Label catchLabel) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1871
        catchLabel.joinFromTry(stack, false);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1872
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1873
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1874
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1875
     * A join in control flow - helper function that makes sure all entry stacks
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1876
     * discovered for the join point so far are equivalent
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1877
     *
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1878
     * MergeStack: we are about to enter a label. If its stack, label.getStack() is null
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1879
     * we have never been here before. Then we are expected to carry a stack with us.
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1880
     *
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1881
     * @param label label
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1882
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1883
    private void joinTo(final Label label) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1884
        assert isReachable();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1885
        label.joinFrom(stack);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1886
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1887
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1888
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1889
     * Register a new label, enter it here.
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1890
     * @param label
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1891
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1892
    void label(final Label label) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1893
        breakLabel(label, -1);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1894
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1895
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1896
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1897
     * Register a new break target label, enter it here.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1898
     *
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1899
     * @param label the label
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1900
     * @param liveLocals the number of live locals at this label
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1901
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1902
    void breakLabel(final Label label, final int liveLocals) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1903
        if (!isReachable()) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1904
            // If we emit a label, and the label's stack is null, it must not be reachable.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1905
            assert (label.getStack() == null) != label.isReachable();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1906
        } else {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1907
            joinTo(label);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1908
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1909
        // Use label's stack as we might have no stack.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1910
        final Label.Stack labelStack = label.getStack();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1911
        stack = labelStack == null ? null : labelStack.clone();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1912
        if(stack != null && label.isBreakTarget() && liveLocals != -1) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1913
            // This has to be done because we might not have another frame to provide us with its firstTemp if the label
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1914
            // is only reachable through a break or continue statement; also in this case, the frame can actually
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1915
            // give us a higher number of live locals, e.g. if it comes from a catch. Typical example:
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1916
            // for(;;) { try{ throw 0; } catch(e) { break; } }.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1917
            // Since the for loop can only be exited through the break in the catch block, it'll bring with it the
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1918
            // "e" as a live local, and we need to trim it off here.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1919
            assert stack.firstTemp >= liveLocals;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1920
            stack.firstTemp = liveLocals;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1921
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1922
        debug_label(label);
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  1923
        method.visitLabel(label.getLabel());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1924
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1925
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1926
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1927
     * Pop element from stack, convert to given type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1928
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1929
     * @param to type to convert to
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1930
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1931
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1932
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  1933
    MethodEmitter convert(final Type to) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1934
        final Type from = peekType();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1935
        final Type type = from.convert(method, to);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1936
        if (type != null) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1937
            if (!from.isEquivalentTo(to)) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1938
                debug("convert", from, "->", to);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1939
            }
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1940
            if (type != from) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1941
                final int l0 = stack.getTopLocalLoad();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1942
                popType();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1943
                pushType(type);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1944
                // NOTE: conversions from a primitive type are considered to preserve the "load" property of the value
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1945
                // on the stack. Otherwise we could introduce temporary locals in a deoptimized rest-of (e.g. doing an
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1946
                // "i < x.length" where "i" is int and ".length" gets deoptimized to long would end up converting i to
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1947
                // long with "ILOAD i; I2L; LSTORE tmp; LLOAD tmp;"). Such additional temporary would cause an error
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1948
                // when restoring the state of the function for rest-of execution, as the not-yet deoptimized variant
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1949
                // would have the (now invalidated) assumption that "x.length" is an int, so it wouldn't have the I2L,
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1950
                // and therefore neither the subsequent LSTORE tmp; LLOAD tmp;. By making sure conversions from a
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1951
                // primitive type don't erase the "load" information, we don't introduce temporaries in the deoptimized
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1952
                // rest-of that didn't exist in the more optimistic version that triggered the deoptimization.
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1953
                // NOTE: as a more general observation, we could theoretically track the operations required to
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1954
                // reproduce any stack value as long as they are all local loads, constant loads, and stack operations.
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1955
                // We won't go there in the current system
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1956
                if(!from.isObject()) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1957
                    stack.markLocalLoad(l0);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1958
                }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  1959
            }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1960
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1961
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1962
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1963
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1964
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1965
     * Helper function - expect two types that are equivalent
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1966
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1967
     * @return common type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1968
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1969
    private Type get2() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1970
        final Type p0 = popType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1971
        final Type p1 = popType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1972
        assert p0.isEquivalentTo(p1) : "expecting equivalent types on stack but got " + p0 + " and " + p1;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1973
        return p0;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1974
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1975
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1976
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1977
     * Helper function - expect two types that are integer types and equivalent
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1978
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1979
     * @return common type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1980
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1981
    private BitwiseType get2i() {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1982
        final BitwiseType p0 = popBitwise();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  1983
        final BitwiseType p1 = popBitwise();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1984
        assert p0.isEquivalentTo(p1) : "expecting equivalent types on stack but got " + p0 + " and " + p1;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1985
        return p0;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1986
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1987
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1988
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1989
     * Helper function - expect two types that are numbers and equivalent
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1990
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1991
     * @return common type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1992
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1993
    private NumericType get2n() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1994
        final NumericType p0 = popNumeric();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1995
        final NumericType p1 = popNumeric();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1996
        assert p0.isEquivalentTo(p1) : "expecting equivalent types on stack but got " + p0 + " and " + p1;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1997
        return p0;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1998
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1999
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2000
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2001
     * Pop two numbers, perform addition and push result
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2002
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2003
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2004
     */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2005
    MethodEmitter add(final int programPoint) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2006
        debug("add");
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2007
        pushType(get2().add(method, programPoint));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2008
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2009
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2010
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2011
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2012
     * Pop two numbers, perform subtraction and push result
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2013
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2014
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2015
     */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2016
    MethodEmitter sub(final int programPoint) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2017
        debug("sub");
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2018
        pushType(get2n().sub(method, programPoint));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2019
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2020
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2021
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2022
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2023
     * Pop two numbers, perform multiplication and push result
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2024
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2025
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2026
     */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2027
    MethodEmitter mul(final int programPoint) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2028
        debug("mul ");
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2029
        pushType(get2n().mul(method, programPoint));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2030
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2031
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2032
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2033
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2034
     * Pop two numbers, perform division and push result
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2035
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2036
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2037
     */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2038
    MethodEmitter div(final int programPoint) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2039
        debug("div");
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2040
        pushType(get2n().div(method, programPoint));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2041
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2042
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2043
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2044
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2045
     * Pop two numbers, calculate remainder and push result
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2046
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2047
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2048
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2049
    MethodEmitter rem(final int programPoint) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2050
        debug("rem");
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2051
        pushType(get2n().rem(method, programPoint));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2052
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2053
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2054
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2055
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2056
     * Retrieve the top <tt>count</tt> types on the stack without modifying it.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2057
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2058
     * @param count number of types to return
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2059
     * @return array of Types
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2060
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2061
    protected Type[] getTypesFromStack(final int count) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2062
        return stack.getTopTypes(count);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2063
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2064
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2065
    int[] getLocalLoadsOnStack(final int from, final int to) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2066
        return stack.getLocalLoads(from, to);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2067
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2068
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2069
    int getStackSize() {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2070
        return stack.size();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2071
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2072
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2073
    int getFirstTemp() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2074
        return stack.firstTemp;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2075
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2076
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2077
    int getUsedSlotsWithLiveTemporaries() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2078
        return stack.getUsedSlotsWithLiveTemporaries();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2079
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2080
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2081
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2082
     * Helper function to generate a function signature based on stack contents
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2083
     * and argument count and return type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2084
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2085
     * @param returnType return type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2086
     * @param argCount   argument count
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2087
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2088
     * @return function signature for stack contents
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2089
     */
16210
8ad1381b69d0 8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents: 16209
diff changeset
  2090
    private String getDynamicSignature(final Type returnType, final int argCount) {
8ad1381b69d0 8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents: 16209
diff changeset
  2091
        final Type[]         paramTypes = new Type[argCount];
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2092
17527
6e45d9c2328c 8014329: Slim down the label stack structure in CodeGenerator
lagergren
parents: 17524
diff changeset
  2093
        int pos = 0;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2094
        for (int i = argCount - 1; i >= 0; i--) {
27099
eceb216332cb 8050977: Java8 Javascript Nashorn exception: no current Global instance for nashorn
sundar
parents: 26890
diff changeset
  2095
            Type pt = stack.peek(pos++);
eceb216332cb 8050977: Java8 Javascript Nashorn exception: no current Global instance for nashorn
sundar
parents: 26890
diff changeset
  2096
            // "erase" specific ScriptObject subtype info - except for NativeArray.
eceb216332cb 8050977: Java8 Javascript Nashorn exception: no current Global instance for nashorn
sundar
parents: 26890
diff changeset
  2097
            // NativeArray is used for array/List/Deque conversion for Java calls.
eceb216332cb 8050977: Java8 Javascript Nashorn exception: no current Global instance for nashorn
sundar
parents: 26890
diff changeset
  2098
            if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
eceb216332cb 8050977: Java8 Javascript Nashorn exception: no current Global instance for nashorn
sundar
parents: 26890
diff changeset
  2099
                !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
eceb216332cb 8050977: Java8 Javascript Nashorn exception: no current Global instance for nashorn
sundar
parents: 26890
diff changeset
  2100
                pt = Type.SCRIPT_OBJECT;
eceb216332cb 8050977: Java8 Javascript Nashorn exception: no current Global instance for nashorn
sundar
parents: 26890
diff changeset
  2101
            }
eceb216332cb 8050977: Java8 Javascript Nashorn exception: no current Global instance for nashorn
sundar
parents: 26890
diff changeset
  2102
            paramTypes[i] = pt;
16210
8ad1381b69d0 8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents: 16209
diff changeset
  2103
        }
8ad1381b69d0 8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents: 16209
diff changeset
  2104
        final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
8ad1381b69d0 8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents: 16209
diff changeset
  2105
        for (int i = 0; i < argCount; i++) {
8ad1381b69d0 8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents: 16209
diff changeset
  2106
            popType(paramTypes[argCount - i - 1]);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2107
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2108
16210
8ad1381b69d0 8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents: 16209
diff changeset
  2109
        return descriptor;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2110
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2111
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24725
diff changeset
  2112
    MethodEmitter invalidateSpecialName(final String name) {
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26377
diff changeset
  2113
        switch (name) {
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26377
diff changeset
  2114
        case "apply":
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26377
diff changeset
  2115
        case "call":
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26377
diff changeset
  2116
            debug("invalidate_name", "name=", name);
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26377
diff changeset
  2117
            load("Function");
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26377
diff changeset
  2118
            invoke(ScriptRuntime.INVALIDATE_RESERVED_BUILTIN_NAME);
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26377
diff changeset
  2119
            break;
26886
18c744ab4df2 8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents: 26768
diff changeset
  2120
        default:
18c744ab4df2 8059211: Changed ArrayData.length accessor to use the protected field and fixed javadoc warnings related to this
lagergren
parents: 26768
diff changeset
  2121
            break;
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24725
diff changeset
  2122
        }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24725
diff changeset
  2123
        return this;
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24725
diff changeset
  2124
    }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24725
diff changeset
  2125
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2126
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2127
     * Generate a dynamic new
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2128
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2129
     * @param argCount  number of arguments
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2130
     * @param flags     callsite flags
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2131
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2132
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2133
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2134
    MethodEmitter dynamicNew(final int argCount, final int flags) {
32048
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2135
        return dynamicNew(argCount, flags, null);
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2136
    }
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2137
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2138
    /**
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2139
     * Generate a dynamic new
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2140
     *
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2141
     * @param argCount  number of arguments
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2142
     * @param flags     callsite flags
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2143
     * @param msg        additional message to be used when reporting error
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2144
     *
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2145
     * @return the method emitter
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2146
     */
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2147
    MethodEmitter dynamicNew(final int argCount, final int flags, final String msg) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2148
        assert !isOptimistic(flags);
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
  2149
        debug("dynamic_new", "argcount=", argCount);
16210
8ad1381b69d0 8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents: 16209
diff changeset
  2150
        final String signature = getDynamicSignature(Type.OBJECT, argCount);
32048
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2151
        method.visitInvokeDynamicInsn(
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2152
                msg != null && msg.length() < LARGE_STRING_THRESHOLD? "dyn:new:" + NameCodec.encode(msg) : "dyn:new",
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2153
                signature, LINKERBOOTSTRAP, flags);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2154
        pushType(Type.OBJECT); //TODO fix result type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2155
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2156
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2157
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2158
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2159
     * Generate a dynamic call
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2160
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2161
     * @param returnType return type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2162
     * @param argCount   number of arguments
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2163
     * @param flags      callsite flags
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2164
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2165
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2166
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2167
    MethodEmitter dynamicCall(final Type returnType, final int argCount, final int flags) {
32048
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2168
        return dynamicCall(returnType, argCount, flags, null);
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2169
    }
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2170
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2171
    /**
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2172
     * Generate a dynamic call
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2173
     *
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2174
     * @param returnType return type
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2175
     * @param argCount   number of arguments
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2176
     * @param flags      callsite flags
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2177
     * @param msg        additional message to be used when reporting error
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2178
     *
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2179
     * @return the method emitter
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2180
     */
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2181
    MethodEmitter dynamicCall(final Type returnType, final int argCount, final int flags, final String msg) {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
  2182
        debug("dynamic_call", "args=", argCount, "returnType=", returnType);
16210
8ad1381b69d0 8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents: 16209
diff changeset
  2183
        final String signature = getDynamicSignature(returnType, argCount); // +1 because the function itself is the 1st parameter for dynamic calls (what you call - call target)
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2184
        debug("   signature", signature);
32048
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2185
        method.visitInvokeDynamicInsn(
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2186
                msg != null && msg.length() < LARGE_STRING_THRESHOLD? "dyn:call:" + NameCodec.encode(msg) : "dyn:call",
8023426b93ab 8073733: TypeError messages with "call" and "new" could be improved
sundar
parents: 30391
diff changeset
  2187
                signature, LINKERBOOTSTRAP, flags);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2188
        pushType(returnType);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2189
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2190
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2191
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2192
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2193
    MethodEmitter dynamicArrayPopulatorCall(final int argCount, final int startIndex) {
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24725
diff changeset
  2194
        debug("populate_array", "args=", argCount, "startIndex=", startIndex);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2195
        final String signature = getDynamicSignature(Type.OBJECT_ARRAY, argCount);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2196
        method.visitInvokeDynamicInsn("populateArray", signature, POPULATE_ARRAY_BOOTSTRAP, startIndex);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2197
        pushType(Type.OBJECT_ARRAY);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2198
        return this;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2199
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2200
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2201
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2202
     * Generate dynamic getter. Pop scope from stack. Push result
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2203
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2204
     * @param valueType type of the value to set
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2205
     * @param name      name of property
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2206
     * @param flags     call site flags
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2207
     * @param isMethod  should it prefer retrieving methods
27976
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2208
     * @param isIndex   is this an index operation?
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2209
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2210
     */
27976
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2211
    MethodEmitter dynamicGet(final Type valueType, final String name, final int flags, final boolean isMethod, final boolean isIndex) {
27368
939ac7c411bc 8047365: Very long function names break codegen
hannesw
parents: 27206
diff changeset
  2212
        if (name.length() > LARGE_STRING_THRESHOLD) { // use getIndex for extremely long names
939ac7c411bc 8047365: Very long function names break codegen
hannesw
parents: 27206
diff changeset
  2213
            return load(name).dynamicGetIndex(valueType, flags, isMethod);
939ac7c411bc 8047365: Very long function names break codegen
hannesw
parents: 27206
diff changeset
  2214
        }
939ac7c411bc 8047365: Very long function names break codegen
hannesw
parents: 27206
diff changeset
  2215
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2216
        debug("dynamic_get", name, valueType, getProgramPoint(flags));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2217
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2218
        Type type = valueType;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2219
        if (type.isObject() || type.isBoolean()) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2220
            type = Type.OBJECT; //promote e.g strings to object generic setter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2221
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2222
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2223
        popType(Type.SCOPE);
27976
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2224
        method.visitInvokeDynamicInsn(dynGetOperation(isMethod, isIndex) + ':' + NameCodec.encode(name),
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2225
                Type.getMethodDescriptor(type, Type.OBJECT), LINKERBOOTSTRAP, flags);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2226
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2227
        pushType(type);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2228
        convert(valueType); //most probably a nop
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2229
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2230
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2231
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2232
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2233
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2234
     * Generate dynamic setter. Pop receiver and property from stack.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2235
     *
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 25865
diff changeset
  2236
     * @param name  name of property
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 25865
diff changeset
  2237
     * @param flags call site flags
27976
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2238
     * @param isIndex is this an index operation?
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2239
     */
27976
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2240
    void dynamicSet(final String name, final int flags, final boolean isIndex) {
27368
939ac7c411bc 8047365: Very long function names break codegen
hannesw
parents: 27206
diff changeset
  2241
        if (name.length() > LARGE_STRING_THRESHOLD) { // use setIndex for extremely long names
939ac7c411bc 8047365: Very long function names break codegen
hannesw
parents: 27206
diff changeset
  2242
            load(name).swap().dynamicSetIndex(flags);
939ac7c411bc 8047365: Very long function names break codegen
hannesw
parents: 27206
diff changeset
  2243
            return;
939ac7c411bc 8047365: Very long function names break codegen
hannesw
parents: 27206
diff changeset
  2244
        }
939ac7c411bc 8047365: Very long function names break codegen
hannesw
parents: 27206
diff changeset
  2245
939ac7c411bc 8047365: Very long function names break codegen
hannesw
parents: 27206
diff changeset
  2246
        assert !isOptimistic(flags);
939ac7c411bc 8047365: Very long function names break codegen
hannesw
parents: 27206
diff changeset
  2247
        debug("dynamic_set", name, peekType());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2248
20928
3ff39d5c8c08 8026137: Fix Issues with Binary Evaluation Order
lagergren
parents: 19095
diff changeset
  2249
        Type type = peekType();
20937
6159db2e332a 8026292: Megamorphic setter fails with boolean value
hannesw
parents: 20928
diff changeset
  2250
        if (type.isObject() || type.isBoolean()) { //promote strings to objects etc
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2251
            type = Type.OBJECT;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2252
            convert(Type.OBJECT); //TODO bad- until we specialize boolean setters,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2253
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2254
        popType(type);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2255
        popType(Type.SCOPE);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2256
27976
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2257
        method.visitInvokeDynamicInsn(dynSetOperation(isIndex) + ':' + NameCodec.encode(name),
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2258
                methodDescriptor(void.class, Object.class, type.getTypeClass()), LINKERBOOTSTRAP, flags);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2259
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2260
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2261
     /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2262
     * Dynamic getter for indexed structures. Pop index and receiver from stack,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2263
     * generate appropriate signatures based on types
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2264
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2265
     * @param result result type for getter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2266
     * @param flags call site flags for getter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2267
     * @param isMethod should it prefer retrieving methods
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2268
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2269
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2270
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2271
    MethodEmitter dynamicGetIndex(final Type result, final int flags, final boolean isMethod) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2272
        assert result.getTypeClass().isPrimitive() || result.getTypeClass() == Object.class;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2273
        debug("dynamic_get_index", peekType(1), "[", peekType(), "]", getProgramPoint(flags));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2274
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2275
        Type resultType = result;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2276
        if (result.isBoolean()) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2277
            resultType = Type.OBJECT; // INT->OBJECT to avoid another dimension of cross products in the getters. TODO
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2278
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2279
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2280
        Type index = peekType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2281
        if (index.isObject() || index.isBoolean()) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2282
            index = Type.OBJECT; //e.g. string->object
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2283
            convert(Type.OBJECT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2284
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2285
        popType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2286
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2287
        popType(Type.OBJECT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2288
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2289
        final String signature = Type.getMethodDescriptor(resultType, Type.OBJECT /*e.g STRING->OBJECT*/, index);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2290
27976
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2291
        method.visitInvokeDynamicInsn(dynGetOperation(isMethod, true), signature, LINKERBOOTSTRAP, flags);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2292
        pushType(resultType);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2293
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2294
        if (result.isBoolean()) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2295
            convert(Type.BOOLEAN);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2296
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2297
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2298
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2299
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2300
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
  2301
    private static String getProgramPoint(final int flags) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2302
        if((flags & CALLSITE_OPTIMISTIC) == 0) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2303
            return "";
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2304
        }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2305
        return "pp=" + String.valueOf((flags & (-1 << CALLSITE_PROGRAM_POINT_SHIFT)) >> CALLSITE_PROGRAM_POINT_SHIFT);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2306
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2307
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2308
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2309
     * Dynamic setter for indexed structures. Pop value, index and receiver from
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2310
     * stack, generate appropriate signature based on types
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2311
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2312
     * @param flags call site flags for setter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2313
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2314
    void dynamicSetIndex(final int flags) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2315
        assert !isOptimistic(flags);
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
  2316
        debug("dynamic_set_index", peekType(2), "[", peekType(1), "] =", peekType());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2317
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2318
        Type value = peekType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2319
        if (value.isObject() || value.isBoolean()) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2320
            value = Type.OBJECT; //e.g. STRING->OBJECT - one descriptor for all object types
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2321
            convert(Type.OBJECT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2322
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2323
        popType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2324
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2325
        Type index = peekType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2326
        if (index.isObject() || index.isBoolean()) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2327
            index = Type.OBJECT; //e.g. string->object
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2328
            convert(Type.OBJECT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2329
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2330
        popType(index);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2331
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2332
        final Type receiver = popType(Type.OBJECT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2333
        assert receiver.isObject();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2334
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2335
        method.visitInvokeDynamicInsn("dyn:setElem|setProp", methodDescriptor(void.class, receiver.getTypeClass(), index.getTypeClass(), value.getTypeClass()), LINKERBOOTSTRAP, flags);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2336
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2337
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2338
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2339
     * Load a key value in the proper form.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2340
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2341
     * @param key
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2342
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2343
    //TODO move this and break it apart
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2344
    MethodEmitter loadKey(final Object key) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2345
        if (key instanceof IdentNode) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2346
            method.visitLdcInsn(((IdentNode) key).getName());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2347
        } else if (key instanceof LiteralNode) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2348
            method.visitLdcInsn(((LiteralNode<?>)key).getString());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2349
        } else {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2350
            method.visitLdcInsn(JSType.toString(key));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2351
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2352
        pushType(Type.OBJECT); //STRING
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2353
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2354
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2355
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2356
     @SuppressWarnings("fallthrough")
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2357
     private static Type fieldType(final String desc) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2358
         switch (desc) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2359
         case "Z":
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2360
         case "B":
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2361
         case "C":
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2362
         case "S":
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2363
         case "I":
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2364
             return Type.INT;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2365
         case "F":
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2366
             assert false;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2367
         case "D":
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2368
             return Type.NUMBER;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2369
         case "J":
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2370
             return Type.LONG;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2371
         default:
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2372
             assert desc.startsWith("[") || desc.startsWith("L") : desc + " is not an object type";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2373
             switch (desc.charAt(0)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2374
             case 'L':
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2375
                 return Type.OBJECT;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2376
             case '[':
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2377
                 return Type.typeFor(Array.newInstance(fieldType(desc.substring(1)).getTypeClass(), 0).getClass());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2378
             default:
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2379
                 assert false;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2380
             }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2381
             return Type.OBJECT;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2382
         }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2383
     }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2384
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2385
     /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2386
      * Generate get for a field access
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2387
      *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2388
      * @param fa the field access
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2389
      *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2390
      * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2391
      */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2392
    MethodEmitter getField(final FieldAccess fa) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2393
        return fa.get(this);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2394
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2395
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2396
     /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2397
      * Generate set for a field access
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2398
      *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2399
      * @param fa the field access
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2400
      */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2401
    void putField(final FieldAccess fa) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2402
        fa.put(this);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2403
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2404
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2405
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2406
     * Get the value of a non-static field, pop the receiver from the stack,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2407
     * push value to the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2408
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2409
     * @param className        class
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2410
     * @param fieldName        field name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2411
     * @param fieldDescriptor  field descriptor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2412
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2413
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2414
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2415
    MethodEmitter getField(final String className, final String fieldName, final String fieldDescriptor) {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
  2416
        debug("getfield", "receiver=", peekType(), className, ".", fieldName, fieldDescriptor);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2417
        final Type receiver = popType();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2418
        assert receiver.isObject();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2419
        method.visitFieldInsn(GETFIELD, className, fieldName, fieldDescriptor);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2420
        pushType(fieldType(fieldDescriptor));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2421
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2422
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2423
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2424
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2425
     * Get the value of a static field, push it to the stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2426
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2427
     * @param className        class
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2428
     * @param fieldName        field name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2429
     * @param fieldDescriptor  field descriptor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2430
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2431
     * @return the method emitter
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2432
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2433
    MethodEmitter getStatic(final String className, final String fieldName, final String fieldDescriptor) {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
  2434
        debug("getstatic", className, ".", fieldName, ".", fieldDescriptor);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2435
        method.visitFieldInsn(GETSTATIC, className, fieldName, fieldDescriptor);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2436
        pushType(fieldType(fieldDescriptor));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2437
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2438
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2439
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2440
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2441
     * Pop value and field from stack and write to a non-static field
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2442
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2443
     * @param className       class
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2444
     * @param fieldName       field name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2445
     * @param fieldDescriptor field descriptor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2446
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2447
    void putField(final String className, final String fieldName, final String fieldDescriptor) {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
  2448
        debug("putfield", "receiver=", peekType(1), "value=", peekType());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2449
        popType(fieldType(fieldDescriptor));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2450
        popType(Type.OBJECT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2451
        method.visitFieldInsn(PUTFIELD, className, fieldName, fieldDescriptor);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2452
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2453
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2454
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2455
     * Pop value from stack and write to a static field
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2456
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2457
     * @param className       class
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2458
     * @param fieldName       field name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2459
     * @param fieldDescriptor field descriptor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2460
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2461
    void putStatic(final String className, final String fieldName, final String fieldDescriptor) {
17246
a1bcf4d2bff1 8013203: A collection of smaller speedups to compilation pipeline
attila
parents: 17233
diff changeset
  2462
        debug("putfield", "value=", peekType());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2463
        popType(fieldType(fieldDescriptor));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2464
        method.visitFieldInsn(PUTSTATIC, className, fieldName, fieldDescriptor);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2465
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2466
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2467
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2468
     * Register line number at a label
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2469
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2470
     * @param line  line number
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2471
     */
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  2472
    void lineNumber(final int line) {
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
  2473
        if (context.getEnv()._debug_lines) {
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  2474
            debug_label("[LINE]", line);
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  2475
            final jdk.internal.org.objectweb.asm.Label l = new jdk.internal.org.objectweb.asm.Label();
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  2476
            method.visitLabel(l);
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  2477
            method.visitLineNumber(line, l);
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17255
diff changeset
  2478
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2479
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2480
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2481
    void beforeJoinPoint(final JoinPredecessor joinPredecessor) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2482
        LocalVariableConversion next = joinPredecessor.getLocalVariableConversion();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2483
        while(next != null) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2484
            final Symbol symbol = next.getSymbol();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2485
            if(next.isLive()) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2486
                emitLocalVariableConversion(next, true);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2487
            } else {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2488
                markDeadLocalVariable(symbol);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2489
            }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2490
            next = next.getNext();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2491
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2492
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2493
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2494
    void beforeTry(final TryNode tryNode, final Label recovery) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2495
        LocalVariableConversion next = tryNode.getLocalVariableConversion();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2496
        while(next != null) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2497
            if(next.isLive()) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2498
                final Type to = emitLocalVariableConversion(next, false);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2499
                recovery.getStack().onLocalStore(to, next.getSymbol().getSlot(to), true);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2500
            }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2501
            next = next.getNext();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2502
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2503
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2504
27976
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2505
    private static String dynGetOperation(final boolean isMethod, final boolean isIndex) {
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2506
        if (isMethod) {
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2507
            return isIndex ? "dyn:getMethod|getElem|getProp" : "dyn:getMethod|getProp|getElem";
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2508
        } else {
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2509
            return isIndex ? "dyn:getElem|getProp|getMethod" : "dyn:getProp|getElem|getMethod";
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2510
        }
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2511
    }
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2512
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2513
    private static String dynSetOperation(final boolean isIndex) {
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2514
        return isIndex ? "dyn:setElem|setProp" : "dyn:setProp|setElem";
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2515
    }
ef54dfb4fc7d 8066669: dust.js performance regression caused by primitive field conversion
hannesw
parents: 27368
diff changeset
  2516
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2517
    private Type emitLocalVariableConversion(final LocalVariableConversion conversion, final boolean onlySymbolLiveValue) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2518
        final Type from = conversion.getFrom();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2519
        final Type to = conversion.getTo();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2520
        final Symbol symbol = conversion.getSymbol();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2521
        assert symbol.isBytecodeLocal();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2522
        if(from == Type.UNDEFINED) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2523
            loadUndefined(to);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2524
        } else {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2525
            load(symbol, from).convert(to);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2526
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2527
        store(symbol, to, onlySymbolLiveValue);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2528
        return to;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2529
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2530
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2531
    /*
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2532
     * Debugging below
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2533
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2534
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2535
    private final FieldAccess ERR_STREAM       = staticField(System.class, "err", PrintStream.class);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2536
    private final Call        PRINT            = virtualCallNoLookup(PrintStream.class, "print", void.class, Object.class);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2537
    private final Call        PRINTLN          = virtualCallNoLookup(PrintStream.class, "println", void.class, Object.class);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2538
    private final Call        PRINT_STACKTRACE = virtualCallNoLookup(Throwable.class, "printStackTrace", void.class);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2539
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2540
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2541
     * Emit a System.err.print statement of whatever is on top of the bytecode stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2542
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2543
     void print() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2544
         getField(ERR_STREAM);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2545
         swap();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2546
         convert(Type.OBJECT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2547
         invoke(PRINT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2548
     }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2549
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2550
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2551
     * Emit a System.err.println statement of whatever is on top of the bytecode stack
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2552
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2553
     void println() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2554
         getField(ERR_STREAM);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2555
         swap();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2556
         convert(Type.OBJECT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2557
         invoke(PRINTLN);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2558
     }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2559
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2560
     /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2561
      * Emit a System.err.print statement
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2562
      * @param string string to print
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2563
      */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2564
     void print(final String string) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2565
         getField(ERR_STREAM);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2566
         load(string);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2567
         invoke(PRINT);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2568
     }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2569
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2570
     /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2571
      * Emit a System.err.println statement
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2572
      * @param string string to print
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2573
      */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2574
     void println(final String string) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2575
         getField(ERR_STREAM);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2576
         load(string);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2577
         invoke(PRINTLN);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2578
     }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2579
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2580
     /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2581
      * Print a stacktrace to S
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2582
      */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2583
     void stacktrace() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2584
         _new(Throwable.class);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2585
         dup();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2586
         invoke(constructorNoLookup(Throwable.class));
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2587
         invoke(PRINT_STACKTRACE);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2588
     }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2589
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2590
    private static int linePrefix = 0;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2591
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2592
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2593
     * Debug function that outputs generated bytecode and stack contents
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2594
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2595
     * @param args debug information to print
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2596
     */
26887
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2597
    @SuppressWarnings("unused")
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2598
    private void debug(final Object... args) {
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
  2599
        if (debug) {
17756
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents: 17527
diff changeset
  2600
            debug(30, args);
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents: 17527
diff changeset
  2601
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2602
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2603
26887
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2604
    private void debug(final String arg) {
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2605
        if (debug) {
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2606
            debug(30, arg);
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2607
        }
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2608
    }
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2609
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2610
    private void debug(final Object arg0, final Object arg1) {
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2611
        if (debug) {
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2612
            debug(30, new Object[] { arg0, arg1 });
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2613
        }
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2614
    }
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2615
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2616
    private void debug(final Object arg0, final Object arg1, final Object arg2) {
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2617
        if (debug) {
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2618
            debug(30, new Object[] { arg0, arg1, arg2 });
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2619
        }
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2620
    }
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2621
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2622
    private void debug(final Object arg0, final Object arg1, final Object arg2, final Object arg3) {
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2623
        if (debug) {
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2624
            debug(30, new Object[] { arg0, arg1, arg2, arg3 });
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2625
        }
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2626
    }
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2627
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2628
    private void debug(final Object arg0, final Object arg1, final Object arg2, final Object arg3, final Object arg4) {
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2629
        if (debug) {
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2630
            debug(30, new Object[] { arg0, arg1, arg2, arg3, arg4 });
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2631
        }
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2632
    }
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2633
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2634
    private void debug(final Object arg0, final Object arg1, final Object arg2, final Object arg3, final Object arg4, final Object arg5) {
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2635
        if (debug) {
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2636
            debug(30, new Object[] { arg0, arg1, arg2, arg3, arg4, arg5 });
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2637
        }
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2638
    }
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2639
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2640
    private void debug(final Object arg0, final Object arg1, final Object arg2, final Object arg3, final Object arg4, final Object arg5, final Object arg6) {
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2641
        if (debug) {
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2642
            debug(30, new Object[] { arg0, arg1, arg2, arg3, arg4, arg5, arg6 });
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2643
        }
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2644
    }
f7e8b7f8f554 8059321: Decrease warmup time by caching common structures that were reused during parse
lagergren
parents: 26886
diff changeset
  2645
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2646
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2647
     * Debug function that outputs generated bytecode and stack contents
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2648
     * for a label - indentation is currently the only thing that differs
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2649
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2650
     * @param args debug information to print
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2651
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2652
    private void debug_label(final Object... args) {
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
  2653
        if (debug) {
17756
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents: 17527
diff changeset
  2654
            debug(22, args);
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents: 17527
diff changeset
  2655
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2656
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2657
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2658
    private void debug(final int padConstant, final Object... args) {
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
  2659
        if (debug) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2660
            final StringBuilder sb = new StringBuilder();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2661
            int pad;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2662
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2663
            sb.append('#');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2664
            sb.append(++linePrefix);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2665
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2666
            pad = 5 - sb.length();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2667
            while (pad > 0) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2668
                sb.append(' ');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2669
                pad--;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2670
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2671
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2672
            if (isReachable() && !stack.isEmpty()) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2673
                sb.append("{");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2674
                sb.append(stack.size());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2675
                sb.append(":");
17527
6e45d9c2328c 8014329: Slim down the label stack structure in CodeGenerator
lagergren
parents: 17524
diff changeset
  2676
                for (int pos = 0; pos < stack.size(); pos++) {
6e45d9c2328c 8014329: Slim down the label stack structure in CodeGenerator
lagergren
parents: 17524
diff changeset
  2677
                    final Type t = stack.peek(pos);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2678
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2679
                    if (t == Type.SCOPE) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2680
                        sb.append("scope");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2681
                    } else if (t == Type.THIS) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2682
                        sb.append("this");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2683
                    } else if (t.isObject()) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2684
                        String desc = t.getDescriptor();
16210
8ad1381b69d0 8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents: 16209
diff changeset
  2685
                        int i;
8ad1381b69d0 8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents: 16209
diff changeset
  2686
                        for (i = 0; desc.charAt(i) == '[' && i < desc.length(); i++) {
8ad1381b69d0 8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents: 16209
diff changeset
  2687
                            sb.append('[');
8ad1381b69d0 8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents: 16209
diff changeset
  2688
                        }
8ad1381b69d0 8007215: Varargs broken for the case of passing more than the arg limit arguments.
lagergren
parents: 16209
diff changeset
  2689
                        desc = desc.substring(i);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2690
                        final int slash = desc.lastIndexOf('/');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2691
                        if (slash != -1) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2692
                            desc = desc.substring(slash + 1, desc.length() - 1);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2693
                        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2694
                        if ("Object".equals(desc)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2695
                            sb.append('O');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2696
                        } else {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2697
                            sb.append(desc);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2698
                        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2699
                    } else {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2700
                        sb.append(t.getDescriptor());
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2701
                    }
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2702
                    final int loadIndex = stack.localLoads[stack.sp - 1 - pos];
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2703
                    if(loadIndex != Label.Stack.NON_LOAD) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2704
                        sb.append('(').append(loadIndex).append(')');
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2705
                    }
17527
6e45d9c2328c 8014329: Slim down the label stack structure in CodeGenerator
lagergren
parents: 17524
diff changeset
  2706
                    if (pos + 1 < stack.size()) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2707
                        sb.append(' ');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2708
                    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2709
                }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2710
                sb.append('}');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2711
                sb.append(' ');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2712
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2713
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2714
            pad = padConstant - sb.length();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2715
            while (pad > 0) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2716
                sb.append(' ');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2717
                pad--;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2718
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2719
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2720
            for (final Object arg : args) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2721
                sb.append(arg);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2722
                sb.append(' ');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2723
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2724
24745
3a6e1477362b 8041434: Add synchronization to the common global constants structure
lagergren
parents: 24744
diff changeset
  2725
            if (context.getEnv() != null) { //early bootstrap code doesn't have inited context yet
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
  2726
                log.info(sb);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2727
                if (DEBUG_TRACE_LINE == linePrefix) {
24744
5290da85fc3d 8038426: Move all loggers from process wide scope into Global scope
lagergren
parents: 24738
diff changeset
  2728
                    new Throwable().printStackTrace(log.getOutputStream());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2729
                }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2730
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2731
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2732
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2733
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2734
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2735
     * Set the current function node being emitted
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2736
     * @param functionNode the function node
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2737
     */
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
  2738
    void setFunctionNode(final FunctionNode functionNode) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2739
        this.functionNode = functionNode;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2740
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2741
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2742
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2743
     * Invoke to enforce assertions preventing load from a local variable slot that's known to not have been written to.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2744
     * Used by CodeGenerator, as it strictly enforces tracking of stores. Simpler uses of MethodEmitter, e.g. those
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2745
     * for creating initializers for structure  classes, array getters, etc. don't have strict tracking of stores,
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2746
     * therefore they would fail if they had this assertion turned on.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2747
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2748
    void setPreventUndefinedLoad() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24745
diff changeset
  2749
        this.preventUndefinedLoad = true;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2750
    }
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  2751
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2752
    private static boolean isOptimistic(final int flags) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2753
        return (flags & CALLSITE_OPTIMISTIC) != 0;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22368
diff changeset
  2754
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  2755
}