nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGeneratorLexicalContext.java
author attila
Wed, 28 Jan 2015 17:58:08 +0100
changeset 28690 78317797ab62
parent 27361 86c4ddb4797b
child 29410 cdfd8fbb2b1d
permissions -rw-r--r--
8067139: Finally blocks inlined incorrectly Reviewed-by: hannesw, lagergren
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
     1
/*
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
     4
 *
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    10
 *
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    15
 * accompanied this code).
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    16
 *
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    20
 *
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    23
 * questions.
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    24
 */
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    25
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    26
package jdk.nashorn.internal.codegen;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    27
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    28
import java.util.ArrayDeque;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    29
import java.util.Collection;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    30
import java.util.Collections;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    31
import java.util.Deque;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    32
import java.util.HashMap;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    33
import java.util.Map;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
    34
import jdk.nashorn.internal.IntDeque;
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    35
import jdk.nashorn.internal.codegen.types.Type;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    36
import jdk.nashorn.internal.ir.Block;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    37
import jdk.nashorn.internal.ir.FunctionNode;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    38
import jdk.nashorn.internal.ir.LexicalContext;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    39
import jdk.nashorn.internal.ir.LexicalContextNode;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    40
import jdk.nashorn.internal.ir.Node;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    41
import jdk.nashorn.internal.ir.Symbol;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    42
import jdk.nashorn.internal.ir.WithNode;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    43
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    44
/**
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    45
 * A lexical context that also tracks if we have any dynamic scopes in the context. Such scopes can have new
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    46
 * variables introduced into them at run time - a with block or a function directly containing an eval call.
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    47
 * Furthermore, this class keeps track of current discard state, which the current method emitter being used is,
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    48
 * the current compile unit, and local variable indexes
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    49
 */
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    50
final class CodeGeneratorLexicalContext extends LexicalContext {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    51
    private int dynamicScopeCount;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    52
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    53
    /** Map of shared scope call sites */
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    54
    private final Map<SharedScopeCall, SharedScopeCall> scopeCalls = new HashMap<>();
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    55
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    56
    /** Compile unit stack - every time we start a sub method (e.g. a split) we push one */
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    57
    private final Deque<CompileUnit> compileUnits = new ArrayDeque<>();
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    58
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    59
    /** Method emitter stack - every time we start a sub method (e.g. a split) we push one */
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    60
    private final Deque<MethodEmitter> methodEmitters = new ArrayDeque<>();
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    61
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    62
    /** The discard stack - whenever we enter a discard node we keep track of its return value status -
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    63
     *  i.e. should we keep it or throw it away */
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    64
    private final Deque<Node> discard = new ArrayDeque<>();
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    65
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
    66
    private final Deque<Map<String, Collection<Label>>> unwarrantedOptimismHandlers = new ArrayDeque<>();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
    67
    private final Deque<StringBuilder> slotTypesDescriptors = new ArrayDeque<>();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
    68
    private final IntDeque splitNodes = new IntDeque();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
    69
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    70
    /** A stack tracking the next free local variable slot in the blocks. There's one entry for every block
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    71
     *  currently on the lexical context stack. */
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    72
    private int[] nextFreeSlots = new int[16];
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    73
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    74
    /** size of next free slot vector */
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    75
    private int nextFreeSlotsSize;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    76
28690
78317797ab62 8067139: Finally blocks inlined incorrectly
attila
parents: 27361
diff changeset
    77
    private boolean isWithBoundary(final Object node) {
24749
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
    78
        return node instanceof Block && !isEmpty() && peek() instanceof WithNode;
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
    79
    }
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
    80
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    81
    @Override
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    82
    public <T extends LexicalContextNode> T push(final T node) {
24749
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
    83
        if (isWithBoundary(node)) {
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
    84
            dynamicScopeCount++;
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
    85
        } else if (node instanceof FunctionNode) {
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
    86
            if (((FunctionNode)node).inDynamicContext()) {
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
    87
                dynamicScopeCount++;
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
    88
            }
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
    89
            splitNodes.push(0);
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
    90
        }
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    91
        return super.push(node);
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    92
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
    93
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
    94
    void enterSplitNode() {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
    95
        splitNodes.getAndIncrement();
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
    96
        pushFreeSlots(methodEmitters.peek().getUsedSlotsWithLiveTemporaries());
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
    97
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
    98
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
    99
    void exitSplitNode() {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   100
        final int count = splitNodes.decrementAndGet();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   101
        assert count >= 0;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   102
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   103
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   104
    @Override
28690
78317797ab62 8067139: Finally blocks inlined incorrectly
attila
parents: 27361
diff changeset
   105
    public <T extends Node> T pop(final T node) {
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   106
        final T popped = super.pop(node);
24749
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
   107
        if (isWithBoundary(node)) {
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
   108
            dynamicScopeCount--;
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
   109
            assert dynamicScopeCount >= 0;
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
   110
        } else if (node instanceof FunctionNode) {
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
   111
            if (((FunctionNode)node).inDynamicContext()) {
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
   112
                dynamicScopeCount--;
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
   113
                assert dynamicScopeCount >= 0;
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24719
diff changeset
   114
            }
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   115
            assert splitNodes.peek() == 0;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   116
            splitNodes.pop();
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   117
        }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   118
        return popped;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   119
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   120
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   121
    boolean inDynamicScope() {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   122
        return dynamicScopeCount > 0;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   123
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   124
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   125
    boolean inSplitNode() {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   126
        return !splitNodes.isEmpty() && splitNodes.peek() > 0;
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   127
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   128
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   129
    MethodEmitter pushMethodEmitter(final MethodEmitter newMethod) {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   130
        methodEmitters.push(newMethod);
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   131
        return newMethod;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   132
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   133
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   134
    MethodEmitter popMethodEmitter(final MethodEmitter oldMethod) {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   135
        assert methodEmitters.peek() == oldMethod;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   136
        methodEmitters.pop();
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   137
        return methodEmitters.isEmpty() ? null : methodEmitters.peek();
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   138
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   139
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   140
    void pushUnwarrantedOptimismHandlers() {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   141
        unwarrantedOptimismHandlers.push(new HashMap<String, Collection<Label>>());
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   142
        slotTypesDescriptors.push(new StringBuilder());
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   143
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   144
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   145
    Map<String, Collection<Label>> getUnwarrantedOptimismHandlers() {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   146
        return unwarrantedOptimismHandlers.peek();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   147
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   148
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   149
    Map<String, Collection<Label>> popUnwarrantedOptimismHandlers() {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   150
        slotTypesDescriptors.pop();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   151
        return unwarrantedOptimismHandlers.pop();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   152
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   153
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   154
    CompileUnit pushCompileUnit(final CompileUnit newUnit) {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   155
        compileUnits.push(newUnit);
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   156
        return newUnit;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   157
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   158
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   159
    CompileUnit popCompileUnit(final CompileUnit oldUnit) {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   160
        assert compileUnits.peek() == oldUnit;
26506
7d55cc7fc301 8057703: More empty classes generated by Nashorn
lagergren
parents: 25865
diff changeset
   161
        final CompileUnit unit = compileUnits.pop();
7d55cc7fc301 8057703: More empty classes generated by Nashorn
lagergren
parents: 25865
diff changeset
   162
        assert unit.hasCode() : "compile unit popped without code";
7d55cc7fc301 8057703: More empty classes generated by Nashorn
lagergren
parents: 25865
diff changeset
   163
        unit.setUsed();
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   164
        return compileUnits.isEmpty() ? null : compileUnits.peek();
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   165
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   166
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   167
    boolean hasCompileUnits() {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   168
        return !compileUnits.isEmpty();
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   169
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   170
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   171
    Collection<SharedScopeCall> getScopeCalls() {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   172
        return Collections.unmodifiableCollection(scopeCalls.values());
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   173
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   174
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   175
    /**
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   176
     * Get a shared static method representing a dynamic scope callsite.
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   177
     *
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   178
     * @param unit current compile unit
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   179
     * @param symbol the symbol
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   180
     * @param valueType the value type of the symbol
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   181
     * @param returnType the return type
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   182
     * @param paramTypes the parameter types
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   183
     * @param flags the callsite flags
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   184
     * @return an object representing a shared scope call
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   185
     */
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   186
    SharedScopeCall getScopeCall(final CompileUnit unit, final Symbol symbol, final Type valueType, final Type returnType, final Type[] paramTypes, final int flags) {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   187
        final SharedScopeCall scopeCall = new SharedScopeCall(symbol, valueType, returnType, paramTypes, flags);
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   188
        if (scopeCalls.containsKey(scopeCall)) {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   189
            return scopeCalls.get(scopeCall);
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   190
        }
22373
ca044992c73f 8030182: scopeCall with -1 as line number
sundar
parents: 17769
diff changeset
   191
        scopeCall.setClassAndName(unit, getCurrentFunction().uniqueName(":scopeCall"));
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   192
        scopeCalls.put(scopeCall, scopeCall);
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   193
        return scopeCall;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   194
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   195
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   196
    /**
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   197
     * Get a shared static method representing a dynamic scope get access.
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   198
     *
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   199
     * @param unit current compile unit
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   200
     * @param symbol the symbol
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   201
     * @param valueType the type of the variable
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   202
     * @param flags the callsite flags
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   203
     * @return an object representing a shared scope call
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   204
     */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   205
    SharedScopeCall getScopeGet(final CompileUnit unit, final Symbol symbol, final Type valueType, final int flags) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   206
        return getScopeCall(unit, symbol, valueType, valueType, null, flags);
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   207
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   208
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   209
    void onEnterBlock(final Block block) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   210
        pushFreeSlots(assignSlots(block, isFunctionBody() ? 0 : getUsedSlotCount()));
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   211
    }
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   212
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   213
    private void pushFreeSlots(final int freeSlots) {
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   214
        if (nextFreeSlotsSize == nextFreeSlots.length) {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   215
            final int[] newNextFreeSlots = new int[nextFreeSlotsSize * 2];
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   216
            System.arraycopy(nextFreeSlots, 0, newNextFreeSlots, 0, nextFreeSlotsSize);
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   217
            nextFreeSlots = newNextFreeSlots;
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   218
        }
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   219
        nextFreeSlots[nextFreeSlotsSize++] = freeSlots;
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   220
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   221
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   222
    int getUsedSlotCount() {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   223
        return nextFreeSlots[nextFreeSlotsSize - 1];
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   224
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   225
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   226
    void releaseSlots() {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   227
        --nextFreeSlotsSize;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   228
        final int undefinedFromSlot = nextFreeSlotsSize == 0 ? 0 : nextFreeSlots[nextFreeSlotsSize - 1];
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   229
        if(!slotTypesDescriptors.isEmpty()) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   230
            slotTypesDescriptors.peek().setLength(undefinedFromSlot);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   231
        }
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   232
        methodEmitters.peek().undefineLocalVariables(undefinedFromSlot, false);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   233
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   234
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   235
    private int assignSlots(final Block block, final int firstSlot) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   236
        int fromSlot = firstSlot;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   237
        final MethodEmitter method = methodEmitters.peek();
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   238
        for (final Symbol symbol : block.getSymbols()) {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   239
            if (symbol.hasSlot()) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   240
                symbol.setFirstSlot(fromSlot);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   241
                final int toSlot = fromSlot + symbol.slotCount();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   242
                method.defineBlockLocalVariable(fromSlot, toSlot);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   243
                fromSlot = toSlot;
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   244
            }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   245
        }
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   246
        return fromSlot;
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   247
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   248
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   249
    static Type getTypeForSlotDescriptor(final char typeDesc) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   250
        // Recognizing both lowercase and uppercase as we're using both to signify symbol boundaries; see
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   251
        // MethodEmitter.markSymbolBoundariesInLvarTypesDescriptor().
27361
86c4ddb4797b 8060204: Fix warnings in Joni and tests
lagergren
parents: 26506
diff changeset
   252
        switch (typeDesc) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   253
            case 'I':
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   254
            case 'i':
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   255
                return Type.INT;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   256
            case 'J':
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   257
            case 'j':
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   258
                return Type.LONG;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   259
            case 'D':
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   260
            case 'd':
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   261
                return Type.NUMBER;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   262
            case 'A':
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   263
            case 'a':
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   264
                return Type.OBJECT;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   265
            case 'U':
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   266
            case 'u':
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   267
                return Type.UNKNOWN;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   268
            default:
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   269
                throw new AssertionError();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   270
        }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   271
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22373
diff changeset
   272
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   273
    void pushDiscard(final Node node) {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   274
        discard.push(node);
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   275
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   276
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   277
    Node popDiscard() {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   278
        return discard.pop();
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   279
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   280
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   281
    Node getCurrentDiscard() {
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   282
        return discard.peek();
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   283
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   284
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   285
    int quickSlot(final Type type) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   286
        return methodEmitters.peek().defineTemporaryLocalVariable(type.getSlots());
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   287
    }
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   288
}
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents:
diff changeset
   289