src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/BinaryContainer.java
author dlong
Tue, 24 Sep 2019 12:47:15 -0400
changeset 58299 6df94ce3ab2f
parent 57786 948ac3112da8
child 58679 9c3209ff7550
permissions -rw-r--r--
8229201: Update Graal Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     1
/*
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57786
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     4
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     8
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    13
 * accompanied this code).
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    14
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    18
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    21
 * questions.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    22
 */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    23
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
    24
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
    25
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    26
package jdk.tools.jaotc.binformat;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    27
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    28
import static org.graalvm.compiler.hotspot.meta.HotSpotAOTProfilingPlugin.Options.TieredAOT;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    29
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    30
import java.io.ByteArrayOutputStream;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    31
import java.io.DataOutputStream;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    32
import java.io.IOException;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    33
import java.util.ArrayList;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    34
import java.util.HashMap;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    35
import java.util.List;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    36
import java.util.Map;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    37
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    38
import jdk.tools.jaotc.binformat.Symbol.Binding;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    39
import jdk.tools.jaotc.binformat.Symbol.Kind;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    40
import jdk.tools.jaotc.binformat.elf.JELFRelocObject;
46260
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
    41
import jdk.tools.jaotc.binformat.macho.JMachORelocObject;
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
    42
import jdk.tools.jaotc.binformat.pecoff.JPECoffRelocObject;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    43
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
43405
1fab8e6866d7 8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents: 42650
diff changeset
    44
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents: 46289
diff changeset
    45
import org.graalvm.compiler.options.OptionValues;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    46
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    47
/**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    48
 * A format-agnostic container class that holds various components of a binary.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    49
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    50
 * <p>
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    51
 * This class holds information necessary to create platform-specific binary containers such as
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents: 46289
diff changeset
    52
 * ELFContainer for Linux and Solaris operating systems or MachOContainer for Mac OS or PEContainer
694c102fd8ed 8177046: Update Graal
iveresov
parents: 46289
diff changeset
    53
 * for MS Windows operating systems.
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    54
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    55
 * <p>
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    56
 * Method APIs provided by this class are used to construct and populate platform-independent
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    57
 * contents of a binary as the first step to create a binary representation of code generated by a
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    58
 * compiler backend such as Graal.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    59
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    60
 * <p>
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    61
 * Methods to record and access code section contents, symbols and relocations are provided.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    62
 */
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
    63
public final class BinaryContainer implements SymbolTable {
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents: 46289
diff changeset
    64
    private final OptionValues graalOptions;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    65
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    66
    private final int codeSegmentSize;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    67
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    68
    private final int codeEntryAlignment;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    69
48172
e26fc5201707 8191437: AOT doesn't work easily after thread local handshakes
dlong
parents: 47798
diff changeset
    70
    private final boolean threadLocalHandshakes;
e26fc5201707 8191437: AOT doesn't work easily after thread local handshakes
dlong
parents: 47798
diff changeset
    71
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    72
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    73
     * Container holding code bits and any other related information.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    74
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    75
    private final CodeContainer codeContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    76
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    77
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    78
     * Container holding global offset data for hotspot linkage.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    79
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    80
    private final ByteContainer extLinkageGOTContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    81
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    82
    /**
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
    83
     * Patched by HotSpot, contains Klass pointers.
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    84
     */
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
    85
    private final ByteContainer klassesGotContainer;
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
    86
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
    87
    /**
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
    88
     * Patched by HotSpot, contains MethodCounters pointers.
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
    89
     */
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
    90
    private final ByteContainer countersGotContainer;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    91
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    92
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    93
     * Patched lazily by hotspot, contains klass/method pointers.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    94
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    95
    private final ByteContainer metadataGotContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    96
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    97
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    98
     * BSS container, contains method state array.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    99
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   100
    private final ByteContainer methodStateContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   101
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   102
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   103
     * Patched by hotspot, contains java object pointers.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   104
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   105
    private final ByteContainer oopGotContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   106
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   107
    // Containers holding read-only data
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   108
    private final ReadOnlyDataContainer configContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   109
    private final ReadOnlyDataContainer metaspaceNamesContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   110
    private final ReadOnlyDataContainer methodsOffsetsContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   111
    private final ReadOnlyDataContainer klassesOffsetsContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   112
    private final ReadOnlyDataContainer klassesDependenciesContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   113
    private final HeaderContainer headerContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   114
    private final ReadOnlyDataContainer stubsOffsetsContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   115
    private final ReadOnlyDataContainer codeSegmentsContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   116
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   117
    // This cannot be read only since we need to patch the metadata at runtime..
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   118
    private final ReadOnlyDataContainer methodMetadataContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   119
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   120
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   121
     * Container containing constant data used by code.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   122
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   123
    private final ReadOnlyDataContainer constantDataContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   124
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   125
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   126
     * Map holding the Strings table.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   127
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   128
    private final Map<String, Integer> offsetStringTable = new HashMap<>();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   129
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   130
    private final Map<String, Integer> metaspaceNames = new HashMap<>();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   131
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   132
    // List of relocation table entries - (symbolName, relocationInfo)
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   133
    private final Map<String, Symbol> symbolTable = new HashMap<>();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   134
    private final Map<Symbol, List<Relocation>> relocationTable = new HashMap<>();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   135
    private final Map<Symbol, Relocation> uniqueRelocationTable = new HashMap<>();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   136
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   137
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   138
     * Mapping of local VM function names to known global symbols generated in the output binary.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   139
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   140
    private static final HashMap<String, String> functionNamesToAOTSymbols = new HashMap<>();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   141
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   142
    //@formatter:off
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   143
    private static final String[][] map = {
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   144
        {"CompilerToVM::Data::SharedRuntime_deopt_blob_unpack",         "_aot_deopt_blob_unpack"},
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   145
        {"CompilerToVM::Data::SharedRuntime_deopt_blob_uncommon_trap",  "_aot_deopt_blob_uncommon_trap"},
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   146
        {"CompilerToVM::Data::SharedRuntime_ic_miss_stub",              "_aot_ic_miss_stub"},
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   147
        {"CompilerToVM::Data::SharedRuntime_handle_wrong_method_stub",  "_aot_handle_wrong_method_stub"},
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   148
        {"SharedRuntime::exception_handler_for_return_address",         "_aot_exception_handler_for_return_address"},
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   149
        {"SharedRuntime::register_finalizer",                           "_aot_register_finalizer"},
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   150
        {"SharedRuntime::OSR_migration_end",                            "_aot_OSR_migration_end"},
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   151
        {"SharedRuntime::enable_stack_reserved_zone",                   "_aot_enable_stack_reserved_zone"},
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   152
        {"CompilerRuntime::resolve_dynamic_invoke",                     "_aot_resolve_dynamic_invoke"},
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   153
        {"CompilerRuntime::resolve_string_by_symbol",                   "_aot_resolve_string_by_symbol"},
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   154
        {"CompilerRuntime::resolve_klass_by_symbol",                    "_aot_resolve_klass_by_symbol"},
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   155
        {"CompilerRuntime::resolve_method_by_symbol_and_load_counters", "_aot_resolve_method_by_symbol_and_load_counters"},
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   156
        {"CompilerRuntime::initialize_klass_by_symbol",                 "_aot_initialize_klass_by_symbol"},
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   157
        {"CompilerRuntime::invocation_event",                           "_aot_invocation_event"},
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   158
        {"CompilerRuntime::backedge_event",                             "_aot_backedge_event"},
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   159
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   160
        {"CompilerToVM::Data::dpow", "_aot_shared_runtime_dpow"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   161
        {"CompilerToVM::Data::dexp", "_aot_shared_runtime_dexp"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   162
        {"CompilerToVM::Data::dcos", "_aot_shared_runtime_dcos"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   163
        {"CompilerToVM::Data::dsin", "_aot_shared_runtime_dsin"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   164
        {"CompilerToVM::Data::dtan", "_aot_shared_runtime_dtan"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   165
        {"CompilerToVM::Data::dlog", "_aot_shared_runtime_dlog"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   166
        {"CompilerToVM::Data::dlog10", "_aot_shared_runtime_dlog10"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   167
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   168
        {"StubRoutines::_jbyte_arraycopy", "_aot_stub_routines_jbyte_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   169
        {"StubRoutines::_jshort_arraycopy", "_aot_stub_routines_jshort_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   170
        {"StubRoutines::_jint_arraycopy", "_aot_stub_routines_jint_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   171
        {"StubRoutines::_jlong_arraycopy", "_aot_stub_routines_jlong_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   172
        {"StubRoutines::_oop_arraycopy", "_aot_stub_routines_oop_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   173
        {"StubRoutines::_oop_arraycopy_uninit", "_aot_stub_routines_oop_arraycopy_uninit"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   174
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   175
        {"StubRoutines::_jbyte_disjoint_arraycopy", "_aot_stub_routines_jbyte_disjoint_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   176
        {"StubRoutines::_jshort_disjoint_arraycopy", "_aot_stub_routines_jshort_disjoint_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   177
        {"StubRoutines::_jint_disjoint_arraycopy", "_aot_stub_routines_jint_disjoint_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   178
        {"StubRoutines::_jlong_disjoint_arraycopy", "_aot_stub_routines_jlong_disjoint_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   179
        {"StubRoutines::_oop_disjoint_arraycopy", "_aot_stub_routines_oop_disjoint_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   180
        {"StubRoutines::_oop_disjoint_arraycopy_uninit", "_aot_stub_routines_oop_disjoint_arraycopy_uninit"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   181
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   182
        {"StubRoutines::_arrayof_jbyte_arraycopy", "_aot_stub_routines_arrayof_jbyte_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   183
        {"StubRoutines::_arrayof_jshort_arraycopy", "_aot_stub_routines_arrayof_jshort_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   184
        {"StubRoutines::_arrayof_jint_arraycopy", "_aot_stub_routines_arrayof_jint_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   185
        {"StubRoutines::_arrayof_jlong_arraycopy", "_aot_stub_routines_arrayof_jlong_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   186
        {"StubRoutines::_arrayof_oop_arraycopy", "_aot_stub_routines_arrayof_oop_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   187
        {"StubRoutines::_arrayof_oop_arraycopy_uninit", "_aot_stub_routines_arrayof_oop_arraycopy_uninit"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   188
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   189
        {"StubRoutines::_arrayof_jbyte_disjoint_arraycopy", "_aot_stub_routines_arrayof_jbyte_disjoint_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   190
        {"StubRoutines::_arrayof_jshort_disjoint_arraycopy", "_aot_stub_routines_arrayof_jshort_disjoint_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   191
        {"StubRoutines::_arrayof_jint_disjoint_arraycopy", "_aot_stub_routines_arrayof_jint_disjoint_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   192
        {"StubRoutines::_arrayof_jlong_disjoint_arraycopy", "_aot_stub_routines_arrayof_jlong_disjoint_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   193
        {"StubRoutines::_arrayof_oop_disjoint_arraycopy", "_aot_stub_routines_arrayof_oop_disjoint_arraycopy"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   194
        {"StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit", "_aot_stub_routines_arrayof_oop_disjoint_arraycopy_uninit"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   195
47084
630d326a3d15 8186850: Update Graal
iveresov
parents: 46949
diff changeset
   196
        {"StubRoutines::_unsafe_arraycopy", "_aot_stub_routines_unsafe_arraycopy"},
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   197
47084
630d326a3d15 8186850: Update Graal
iveresov
parents: 46949
diff changeset
   198
        {"StubRoutines::_checkcast_arraycopy", "_aot_stub_routines_checkcast_arraycopy"},
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   199
47798
9fe9292f5931 8190710: Update Graal
dlong
parents: 47668
diff changeset
   200
        {"StubRoutines::_generic_arraycopy", "_aot_stub_routines_generic_arraycopy"},
9fe9292f5931 8190710: Update Graal
dlong
parents: 47668
diff changeset
   201
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   202
        {"StubRoutines::_aescrypt_encryptBlock", "_aot_stub_routines_aescrypt_encryptBlock"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   203
        {"StubRoutines::_aescrypt_decryptBlock", "_aot_stub_routines_aescrypt_decryptBlock"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   204
        {"StubRoutines::_cipherBlockChaining_encryptAESCrypt", "_aot_stub_routines_cipherBlockChaining_encryptAESCrypt"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   205
        {"StubRoutines::_cipherBlockChaining_decryptAESCrypt", "_aot_stub_routines_cipherBlockChaining_decryptAESCrypt"},
57786
948ac3112da8 8225625: AES Electronic Codebook (ECB) encryption and decryption optimization using AVX512 + VAES instructions
srukmannagar
parents: 52033
diff changeset
   206
        {"StubRoutines::_electronicCodeBook_encryptAESCrypt", "_aot_stub_routines_electronicCodeBook_encryptAESCrypt"},
948ac3112da8 8225625: AES Electronic Codebook (ECB) encryption and decryption optimization using AVX512 + VAES instructions
srukmannagar
parents: 52033
diff changeset
   207
        {"StubRoutines::_electronicCodeBook_decryptAESCrypt", "_aot_stub_routines_electronicCodeBook_decryptAESCrypt"},
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   208
        {"StubRoutines::_updateBytesCRC32", "_aot_stub_routines_update_bytes_crc32"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   209
        {"StubRoutines::_crc_table_adr", "_aot_stub_routines_crc_table_adr"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   210
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   211
        {"StubRoutines::_sha1_implCompress", "_aot_stub_routines_sha1_implCompress" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   212
        {"StubRoutines::_sha1_implCompressMB", "_aot_stub_routines_sha1_implCompressMB" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   213
        {"StubRoutines::_sha256_implCompress", "_aot_stub_routines_sha256_implCompress" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   214
        {"StubRoutines::_sha256_implCompressMB", "_aot_stub_routines_sha256_implCompressMB" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   215
        {"StubRoutines::_sha512_implCompress", "_aot_stub_routines_sha512_implCompress" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   216
        {"StubRoutines::_sha512_implCompressMB", "_aot_stub_routines_sha512_implCompressMB" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   217
        {"StubRoutines::_multiplyToLen", "_aot_stub_routines_multiplyToLen" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   218
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   219
        {"StubRoutines::_counterMode_AESCrypt", "_aot_stub_routines_counterMode_AESCrypt" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   220
        {"StubRoutines::_ghash_processBlocks", "_aot_stub_routines_ghash_processBlocks" },
50860
480a96a43b62 8205528: Base64 encoding algorithm using AVX512 instructions
kvn
parents: 50104
diff changeset
   221
        {"StubRoutines::_base64_encodeBlock", "_aot_stub_routines_base64_encodeBlock" },
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   222
        {"StubRoutines::_crc32c_table_addr", "_aot_stub_routines_crc32c_table_addr" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   223
        {"StubRoutines::_updateBytesCRC32C", "_aot_stub_routines_updateBytesCRC32C" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   224
        {"StubRoutines::_updateBytesAdler32", "_aot_stub_routines_updateBytesAdler32" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   225
        {"StubRoutines::_squareToLen", "_aot_stub_routines_squareToLen" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   226
        {"StubRoutines::_mulAdd", "_aot_stub_routines_mulAdd" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   227
        {"StubRoutines::_montgomeryMultiply", "_aot_stub_routines_montgomeryMultiply" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   228
        {"StubRoutines::_montgomerySquare", "_aot_stub_routines_montgomerySquare" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   229
        {"StubRoutines::_vectorizedMismatch", "_aot_stub_routines_vectorizedMismatch" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   230
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   231
        {"StubRoutines::_throw_delayed_StackOverflowError_entry", "_aot_stub_routines_throw_delayed_StackOverflowError_entry" },
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   232
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   233
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   234
        {"os::javaTimeMillis", "_aot_os_javaTimeMillis"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   235
        {"os::javaTimeNanos", "_aot_os_javaTimeNanos"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   236
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   237
        {"JVMCIRuntime::monitorenter", "_aot_jvmci_runtime_monitorenter"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   238
        {"JVMCIRuntime::monitorexit", "_aot_jvmci_runtime_monitorexit"},
49837
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 48172
diff changeset
   239
        {"JVMCIRuntime::object_notify", "_aot_object_notify"},
32ba0c867a46 8200196: [Graal] implement Object.notify/notifyAll intrinsics
dlong
parents: 48172
diff changeset
   240
        {"JVMCIRuntime::object_notifyAll", "_aot_object_notifyAll"},
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   241
        {"JVMCIRuntime::log_object", "_aot_jvmci_runtime_log_object"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   242
        {"JVMCIRuntime::log_printf", "_aot_jvmci_runtime_log_printf"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   243
        {"JVMCIRuntime::vm_message", "_aot_jvmci_runtime_vm_message"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   244
        {"JVMCIRuntime::new_instance", "_aot_jvmci_runtime_new_instance"},
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51436
diff changeset
   245
        {"JVMCIRuntime::new_array", "_aot_jvmci_runtime_new_array"},
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   246
        {"JVMCIRuntime::new_multi_array", "_aot_jvmci_runtime_new_multi_array"},
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51436
diff changeset
   247
        {"JVMCIRuntime::dynamic_new_instance", "_aot_jvmci_runtime_dynamic_new_instance"},
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51436
diff changeset
   248
        {"JVMCIRuntime::dynamic_new_array", "_aot_jvmci_runtime_dynamic_new_array"},
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51436
diff changeset
   249
        {"JVMCIRuntime::new_instance_or_null", "_aot_jvmci_runtime_new_instance_or_null"},
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51436
diff changeset
   250
        {"JVMCIRuntime::new_array_or_null", "_aot_jvmci_runtime_new_array_or_null"},
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51436
diff changeset
   251
        {"JVMCIRuntime::new_multi_array_or_null", "_aot_jvmci_runtime_new_multi_array_or_null"},
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51436
diff changeset
   252
        {"JVMCIRuntime::dynamic_new_instance_or_null", "_aot_jvmci_runtime_dynamic_new_instance_or_null"},
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51436
diff changeset
   253
        {"JVMCIRuntime::dynamic_new_array_or_null", "_aot_jvmci_runtime_dynamic_new_array_or_null"},
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51436
diff changeset
   254
        {"JVMCIRuntime::log_primitive", "_aot_jvmci_runtime_log_primitive"},
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   255
        {"JVMCIRuntime::validate_object", "_aot_jvmci_runtime_validate_object"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   256
        {"JVMCIRuntime::write_barrier_pre", "_aot_jvmci_runtime_write_barrier_pre"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   257
        {"JVMCIRuntime::identity_hash_code", "_aot_jvmci_runtime_identity_hash_code"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   258
        {"JVMCIRuntime::write_barrier_post", "_aot_jvmci_runtime_write_barrier_post"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   259
        {"JVMCIRuntime::thread_is_interrupted", "_aot_jvmci_runtime_thread_is_interrupted"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   260
        {"JVMCIRuntime::exception_handler_for_pc", "_aot_jvmci_runtime_exception_handler_for_pc"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   261
        {"JVMCIRuntime::test_deoptimize_call_int", "_aot_jvmci_runtime_test_deoptimize_call_int"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   262
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   263
        {"JVMCIRuntime::throw_and_post_jvmti_exception",      "_aot_jvmci_runtime_throw_and_post_jvmti_exception"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   264
        {"JVMCIRuntime::throw_klass_external_name_exception", "_aot_jvmci_runtime_throw_klass_external_name_exception"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   265
        {"JVMCIRuntime::throw_class_cast_exception",          "_aot_jvmci_runtime_throw_class_cast_exception"},
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   266
52033
d6aa9ea2405d 8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents: 51436
diff changeset
   267
        {"JVMCIRuntime::vm_error", "_aot_jvmci_runtime_vm_error"}
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   268
    };
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   269
    //@formatter:on
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   270
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   271
    static {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   272
        for (String[] entry : map) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   273
            functionNamesToAOTSymbols.put(entry[0], entry[1]);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   274
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   275
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   276
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   277
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   278
     * Allocates a {@code BinaryContainer} object whose content will be generated in a file with the
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   279
     * prefix {@code prefix}. It also initializes internal code container, symbol table and
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   280
     * relocation tables.
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents: 46289
diff changeset
   281
     *
694c102fd8ed 8177046: Update Graal
iveresov
parents: 46289
diff changeset
   282
     * @param graalOptions
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   283
     */
51206
14b870bda24f 8207069: [AOT] we should check that VM uses the same GC as one used for AOT library generation.
kvn
parents: 51126
diff changeset
   284
    public BinaryContainer(OptionValues graalOptions, GraalHotSpotVMConfig graalHotSpotVMConfig, GraphBuilderConfiguration graphBuilderConfig, int gc, String jvmVersion) {
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents: 46289
diff changeset
   285
        this.graalOptions = graalOptions;
694c102fd8ed 8177046: Update Graal
iveresov
parents: 46289
diff changeset
   286
43405
1fab8e6866d7 8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents: 42650
diff changeset
   287
        this.codeSegmentSize = graalHotSpotVMConfig.codeSegmentSize;
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   288
        if (codeSegmentSize < 1 || codeSegmentSize > 1024) {
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   289
            throw new InternalError("codeSegmentSize is not in range [1, 1024] bytes: (" + codeSegmentSize + "), update JPECoffRelocObject");
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   290
        }
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   291
        if ((codeSegmentSize & (codeSegmentSize - 1)) != 0) {
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   292
            throw new InternalError("codeSegmentSize is not power of 2: (" + codeSegmentSize + "), update JPECoffRelocObject");
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   293
        }
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   294
43405
1fab8e6866d7 8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents: 42650
diff changeset
   295
        this.codeEntryAlignment = graalHotSpotVMConfig.codeEntryAlignment;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   296
48172
e26fc5201707 8191437: AOT doesn't work easily after thread local handshakes
dlong
parents: 47798
diff changeset
   297
        this.threadLocalHandshakes = graalHotSpotVMConfig.threadLocalHandshakes;
e26fc5201707 8191437: AOT doesn't work easily after thread local handshakes
dlong
parents: 47798
diff changeset
   298
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   299
        // Section unique name is limited to 8 characters due to limitation on Windows.
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   300
        // Name could be longer but only first 8 characters are stored on Windows.
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   301
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   302
        // read only, code
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   303
        codeContainer = new CodeContainer(".text", this);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   304
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   305
        // read only, info
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   306
        headerContainer = new HeaderContainer(jvmVersion, new ReadOnlyDataContainer(".header", this));
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   307
        configContainer = new ReadOnlyDataContainer(".config", this);
46260
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   308
        metaspaceNamesContainer = new ReadOnlyDataContainer(".meta.names", this);
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   309
        methodsOffsetsContainer = new ReadOnlyDataContainer(".meth.offsets", this);
46260
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   310
        klassesOffsetsContainer = new ReadOnlyDataContainer(".kls.offsets", this);
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   311
        klassesDependenciesContainer = new ReadOnlyDataContainer(".kls.dependencies", this);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   312
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   313
        stubsOffsetsContainer = new ReadOnlyDataContainer(".stubs.offsets", this);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   314
        codeSegmentsContainer = new ReadOnlyDataContainer(".code.segments", this);
46260
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   315
        constantDataContainer = new ReadOnlyDataContainer(".meth.constdata", this);
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   316
        methodMetadataContainer = new ReadOnlyDataContainer(".meth.metadata", this);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   317
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   318
        // writable sections
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   319
        oopGotContainer = new ByteContainer(".oop.got", this);
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   320
        klassesGotContainer = new ByteContainer(".kls.got", this);
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   321
        countersGotContainer = new ByteContainer(".cnt.got", this);
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   322
        metadataGotContainer = new ByteContainer(".meta.got", this);
46260
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   323
        methodStateContainer = new ByteContainer(".meth.state", this);
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   324
        extLinkageGOTContainer = new ByteContainer(".got.linkage", this);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   325
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   326
        addGlobalSymbols();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   327
51206
14b870bda24f 8207069: [AOT] we should check that VM uses the same GC as one used for AOT library generation.
kvn
parents: 51126
diff changeset
   328
        recordConfiguration(graalHotSpotVMConfig, graphBuilderConfig, gc);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   329
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   330
51206
14b870bda24f 8207069: [AOT] we should check that VM uses the same GC as one used for AOT library generation.
kvn
parents: 51126
diff changeset
   331
    private void recordConfiguration(GraalHotSpotVMConfig graalHotSpotVMConfig, GraphBuilderConfiguration graphBuilderConfig, int gc) {
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   332
        // @Checkstyle: stop
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   333
        // @formatter:off
43405
1fab8e6866d7 8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents: 42650
diff changeset
   334
        boolean[] booleanFlags = { graalHotSpotVMConfig.cAssertions, // Debug VM
1fab8e6866d7 8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents: 42650
diff changeset
   335
                                   graalHotSpotVMConfig.useCompressedOops,
1fab8e6866d7 8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents: 42650
diff changeset
   336
                                   graalHotSpotVMConfig.useCompressedClassPointers,
1fab8e6866d7 8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents: 42650
diff changeset
   337
                                   graalHotSpotVMConfig.compactFields,
1fab8e6866d7 8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents: 42650
diff changeset
   338
                                   graalHotSpotVMConfig.useTLAB,
1fab8e6866d7 8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents: 42650
diff changeset
   339
                                   graalHotSpotVMConfig.useBiasedLocking,
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents: 46289
diff changeset
   340
                                   TieredAOT.getValue(graalOptions),
43405
1fab8e6866d7 8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents: 42650
diff changeset
   341
                                   graalHotSpotVMConfig.enableContended,
1fab8e6866d7 8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents: 42650
diff changeset
   342
                                   graalHotSpotVMConfig.restrictContended,
48172
e26fc5201707 8191437: AOT doesn't work easily after thread local handshakes
dlong
parents: 47798
diff changeset
   343
                                   graphBuilderConfig.omitAssertions(),
e26fc5201707 8191437: AOT doesn't work easily after thread local handshakes
dlong
parents: 47798
diff changeset
   344
                                   graalHotSpotVMConfig.threadLocalHandshakes
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   345
        };
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   346
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents: 46289
diff changeset
   347
        int[] intFlags         = { graalHotSpotVMConfig.getOopEncoding().getShift(),
694c102fd8ed 8177046: Update Graal
iveresov
parents: 46289
diff changeset
   348
                                   graalHotSpotVMConfig.getKlassEncoding().getShift(),
43405
1fab8e6866d7 8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents: 42650
diff changeset
   349
                                   graalHotSpotVMConfig.contendedPaddingWidth,
1fab8e6866d7 8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents: 42650
diff changeset
   350
                                   graalHotSpotVMConfig.fieldsAllocationStyle,
46344
694c102fd8ed 8177046: Update Graal
iveresov
parents: 46289
diff changeset
   351
                                   1 << graalHotSpotVMConfig.logMinObjAlignment(),
43405
1fab8e6866d7 8168792: [AOT] problems in MethodHandle with aot-compiled java.base
iveresov
parents: 42650
diff changeset
   352
                                   graalHotSpotVMConfig.codeSegmentSize,
51206
14b870bda24f 8207069: [AOT] we should check that VM uses the same GC as one used for AOT library generation.
kvn
parents: 51126
diff changeset
   353
                                   gc
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   354
        };
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   355
        // @formatter:on
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   356
        // @Checkstyle: resume
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   357
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   358
        byte[] booleanFlagsAsBytes = flagsToByteArray(booleanFlags);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   359
        int size0 = configContainer.getByteStreamSize();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   360
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   361
        // @formatter:off
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   362
        int computedSize = booleanFlagsAsBytes.length * Byte.BYTES    + // size of boolean flags
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   363
                           intFlags.length            * Integer.BYTES + // size of int flags
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   364
                           Integer.BYTES;                               // size of the "computedSize"
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   365
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   366
        configContainer.appendInt(computedSize).
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   367
                        appendInts(intFlags).
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   368
                        appendBytes(booleanFlagsAsBytes);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   369
        // @formatter:on
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   370
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   371
        int size = configContainer.getByteStreamSize() - size0;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   372
        assert size == computedSize;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   373
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   374
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   375
    private static byte[] flagsToByteArray(boolean[] flags) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   376
        byte[] byteArray = new byte[flags.length];
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   377
        for (int i = 0; i < flags.length; ++i) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   378
            byteArray[i] = boolToByte(flags[i]);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   379
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   380
        return byteArray;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   381
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   382
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   383
    private static byte boolToByte(boolean flag) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   384
        return (byte) (flag ? 1 : 0);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   385
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   386
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   387
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   388
     * Free some memory.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   389
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   390
    public void freeMemory() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   391
        offsetStringTable.clear();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   392
        metaspaceNames.clear();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   393
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   394
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   395
    /*
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   396
     * Global symbol names in generated DSO corresponding to VM's symbols. VM needs to look up this
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   397
     * symbol in DSO and link it with VM's corresponding symbol: store VM's symbol address or value
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   398
     * in the named GOT cell.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   399
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   400
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   401
    public static String getCardTableAddressSymbolName() {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   402
        return "_aot_card_table_address";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   403
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   404
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   405
    public static String getHeapTopAddressSymbolName() {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   406
        return "_aot_heap_top_address";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   407
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   408
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   409
    public static String getHeapEndAddressSymbolName() {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   410
        return "_aot_heap_end_address";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   411
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   412
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   413
    public static String getCrcTableAddressSymbolName() {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   414
        return "_aot_stub_routines_crc_table_adr";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   415
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   416
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   417
    public static String getPollingPageSymbolName() {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   418
        return "_aot_polling_page";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   419
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   420
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   421
    public static String getResolveStaticEntrySymbolName() {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   422
        return "_resolve_static_entry";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   423
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   424
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   425
    public static String getResolveVirtualEntrySymbolName() {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   426
        return "_resolve_virtual_entry";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   427
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   428
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   429
    public static String getResolveOptVirtualEntrySymbolName() {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   430
        return "_resolve_opt_virtual_entry";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   431
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   432
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   433
    public static String getNarrowKlassBaseAddressSymbolName() {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   434
        return "_aot_narrow_klass_base_address";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   435
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   436
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   437
    public static String getNarrowOopBaseAddressSymbolName() {
43435
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 43405
diff changeset
   438
        return "_aot_narrow_oop_base_address";
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 43405
diff changeset
   439
    }
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 43405
diff changeset
   440
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   441
    public static String getLogOfHeapRegionGrainBytesSymbolName() {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   442
        return "_aot_log_of_heap_region_grain_bytes";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   443
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   444
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   445
    public static String getInlineContiguousAllocationSupportedSymbolName() {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   446
        return "_aot_inline_contiguous_allocation_supported";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   447
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   448
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   449
    public int getCodeSegmentSize() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   450
        return codeSegmentSize;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   451
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   452
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   453
    public int getCodeEntryAlignment() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   454
        return codeEntryAlignment;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   455
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   456
48172
e26fc5201707 8191437: AOT doesn't work easily after thread local handshakes
dlong
parents: 47798
diff changeset
   457
    public boolean getThreadLocalHandshakes() {
e26fc5201707 8191437: AOT doesn't work easily after thread local handshakes
dlong
parents: 47798
diff changeset
   458
        return threadLocalHandshakes;
e26fc5201707 8191437: AOT doesn't work easily after thread local handshakes
dlong
parents: 47798
diff changeset
   459
    }
e26fc5201707 8191437: AOT doesn't work easily after thread local handshakes
dlong
parents: 47798
diff changeset
   460
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   461
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   462
     * Gets the global AOT symbol associated with the function name.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   463
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   464
     * @param functionName function name
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   465
     * @return AOT symbol for the given function name, or null if there is no mapping.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   466
     */
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   467
    public static String getAOTSymbolForVMFunctionName(String functionName) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   468
        return functionNamesToAOTSymbols.get(functionName);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   469
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   470
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   471
    private void addGlobalSymbols() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   472
        // Create global symbols for all containers.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   473
        createContainerSymbol(codeContainer);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   474
        createContainerSymbol(configContainer);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   475
        createContainerSymbol(methodsOffsetsContainer);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   476
        createContainerSymbol(klassesOffsetsContainer);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   477
        createContainerSymbol(klassesDependenciesContainer);
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   478
        createContainerSymbol(klassesGotContainer);
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   479
        createContainerSymbol(countersGotContainer);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   480
        createContainerSymbol(metadataGotContainer);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   481
        createContainerSymbol(methodStateContainer);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   482
        createContainerSymbol(oopGotContainer);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   483
        createContainerSymbol(metaspaceNamesContainer);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   484
        createContainerSymbol(methodMetadataContainer);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   485
        createContainerSymbol(stubsOffsetsContainer);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   486
        createContainerSymbol(headerContainer.getContainer());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   487
        createContainerSymbol(codeSegmentsContainer);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   488
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   489
        createGotSymbol(getResolveStaticEntrySymbolName());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   490
        createGotSymbol(getResolveVirtualEntrySymbolName());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   491
        createGotSymbol(getResolveOptVirtualEntrySymbolName());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   492
        createGotSymbol(getCardTableAddressSymbolName());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   493
        createGotSymbol(getHeapTopAddressSymbolName());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   494
        createGotSymbol(getHeapEndAddressSymbolName());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   495
        createGotSymbol(getNarrowKlassBaseAddressSymbolName());
43435
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 43405
diff changeset
   496
        createGotSymbol(getNarrowOopBaseAddressSymbolName());
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   497
        createGotSymbol(getPollingPageSymbolName());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   498
        createGotSymbol(getLogOfHeapRegionGrainBytesSymbolName());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   499
        createGotSymbol(getInlineContiguousAllocationSupportedSymbolName());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   500
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   501
        for (HashMap.Entry<String, String> entry : functionNamesToAOTSymbols.entrySet()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   502
            createGotSymbol(entry.getValue());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   503
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   504
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   505
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   506
    /**
47084
630d326a3d15 8186850: Update Graal
iveresov
parents: 46949
diff changeset
   507
     * Creates a global symbol of the form {@code "A" + container name}. Note, linker on Windows
630d326a3d15 8186850: Update Graal
iveresov
parents: 46949
diff changeset
   508
     * does not allow names which start with '.'
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   509
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   510
     * @param container container to create a symbol for
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   511
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   512
    private static void createContainerSymbol(ByteContainer container) {
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   513
        container.createSymbol(0, Kind.OBJECT, Binding.GLOBAL, 0, "A" + container.getContainerName());
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   514
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   515
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   516
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   517
     * Creates a global GOT symbol of the form {@code "got." + name}.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   518
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   519
     * @param name name for the GOT symbol
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   520
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   521
    private void createGotSymbol(String name) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   522
        String s = "got." + name;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   523
        Symbol gotSymbol = extLinkageGOTContainer.createGotSymbol(s);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   524
        extLinkageGOTContainer.createSymbol(gotSymbol.getOffset(), Kind.OBJECT, Binding.GLOBAL, 8, name);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   525
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   526
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   527
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   528
     * Create a platform-specific binary file representing the content of the
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   529
     * {@code BinaryContainer} object.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   530
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   531
     * This method is called after creating and performing any necessary changes to the contents of
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   532
     * code stream, symbol tables and relocation tables is completely finalized
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   533
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   534
     * @param outputFileName name of output file
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   535
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   536
     * @throws IOException in case of file creation failure
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   537
     */
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   538
    public void createBinary(String outputFileName) throws IOException {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   539
        String osName = System.getProperty("os.name");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   540
        switch (osName) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   541
            case "Linux":
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   542
            case "SunOS":
50104
4ea7917929b9 8185505: AArch64: Port AOT to AArch64
aph
parents: 49837
diff changeset
   543
                JELFRelocObject elfobj = JELFRelocObject.newInstance(this, outputFileName);
46260
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   544
                elfobj.createELFRelocObject(relocationTable, symbolTable.values());
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   545
                break;
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   546
            case "Mac OS X":
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   547
                JMachORelocObject machobj = new JMachORelocObject(this, outputFileName);
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   548
                machobj.createMachORelocObject(relocationTable, symbolTable.values());
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   549
                break;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   550
            default:
46260
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   551
                if (osName.startsWith("Windows")) {
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   552
                    JPECoffRelocObject pecoffobj = new JPECoffRelocObject(this, outputFileName);
46260
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   553
                    pecoffobj.createPECoffRelocObject(relocationTable, symbolTable.values());
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   554
                    break;
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   555
                } else {
46260
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   556
                    throw new InternalError("Unsupported platform: " + osName);
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   557
                }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   558
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   559
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   560
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   561
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   562
     * Add symbol to the symbol table. If the existing symbol is undefined and the specified symbol
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   563
     * is not undefined, replace the existing symbol information with that specified.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   564
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   565
     * @param symInfo symbol information to be added
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   566
     */
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   567
    @Override
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   568
    public void addSymbol(Symbol symInfo) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   569
        if (symInfo.getName().startsWith("got.") && !(symInfo instanceof GotSymbol)) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   570
            throw new InternalError("adding got. without being GotSymbol");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   571
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   572
        if (symbolTable.containsKey(symInfo.getName())) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   573
            throw new InternalError("Symbol: " + symInfo.getName() + " already exists in SymbolTable");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   574
        } else {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   575
            // System.out.println("# Symbol [" + name + "] [" + symInfo.getValue() + "] [" +
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   576
            // symInfo.getSection().getContainerName() + "] [" + symInfo.getSize() + "]");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   577
            symbolTable.put(symInfo.getName(), symInfo);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   578
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   579
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   580
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   581
    public boolean addStringOffset(String name, Integer offset) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   582
        offsetStringTable.put(name, offset);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   583
        return true;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   584
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   585
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   586
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   587
     * Add relocation entry for {@code symName}. Multiple relocation entries for a given symbol may
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   588
     * exist.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   589
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   590
     * @param info relocation information to be added
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   591
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   592
    public void addRelocation(Relocation info) {
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   593
        // System.out.println("# Relocation [" + info.getSymbol() + "] [" + info.getOffset() + "] ["
091c0d22e735 8206992: Update Graal
iveresov
parents: 51206
diff changeset
   594
        // +
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   595
        // info.getSection().getContainerName() + "] [" + info.getSymbol().getName() + "] [" +
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   596
        // info.getSymbol().getOffset() + " @ " + info.getSymbol().getSection().getContainerName() +
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   597
        // "]");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   598
        if (relocationTable.containsKey(info.getSymbol())) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   599
            relocationTable.get(info.getSymbol()).add(info);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   600
        } else if (uniqueRelocationTable.containsKey(info.getSymbol())) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   601
            // promote
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   602
            ArrayList<Relocation> list = new ArrayList<>(2);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   603
            list.add(uniqueRelocationTable.get(info.getSymbol()));
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   604
            list.add(info);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   605
            relocationTable.put(info.getSymbol(), list);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   606
            uniqueRelocationTable.remove(info.getSymbol());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   607
        } else {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   608
            uniqueRelocationTable.put(info.getSymbol(), info);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   609
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   610
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   611
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   612
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   613
     * Get symbol with name {@code symName}.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   614
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   615
     * @param symName name of symbol for which symbol table information is being queried
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   616
     * @return success or failure of insertion operation
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   617
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   618
    @Override
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   619
    public Symbol getSymbol(String symName) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   620
        return symbolTable.get(symName);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   621
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   622
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   623
    @Override
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   624
    public Symbol createSymbol(int offset, Kind kind, Binding binding, int size, String name) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   625
        if (kind != Kind.NATIVE_FUNCTION) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   626
            throw new UnsupportedOperationException("Must be external functions: " + name);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   627
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   628
        Symbol symbol = new Symbol(offset, kind, binding, null, size, name);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   629
        addSymbol(symbol);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   630
        return symbol;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   631
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   632
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   633
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   634
     * Get offset in got section with name {@code symName}.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   635
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   636
     * @param name for which String table information is being queried
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   637
     * @return success or failure of insertion operation
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   638
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   639
    public Integer getStringOffset(String name) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   640
        return offsetStringTable.get(name);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   641
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   642
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   643
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   644
     * Insert {@code targetCode} to code stream with {@code size} at {@code offset}.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   645
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   646
     * @param targetCode byte array of native code
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   647
     * @param offset offset at which {@code targetCode} is to be inserted
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   648
     * @param size size of {@code targetCode}
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   649
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   650
    private static void appendBytes(ByteContainer byteContainer, byte[] targetCode, int offset, int size) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   651
        byteContainer.appendBytes(targetCode, offset, size);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   652
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   653
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   654
    public void appendCodeBytes(byte[] targetCode, int offset, int size) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   655
        appendBytes(codeContainer, targetCode, offset, size);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   656
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   657
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   658
    public void appendIntToCode(int value) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   659
        codeContainer.appendInt(value);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   660
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   661
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   662
    public int appendExtLinkageGotBytes(byte[] bytes, int offset, int size) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   663
        int startOffset = extLinkageGOTContainer.getByteStreamSize();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   664
        appendBytes(extLinkageGOTContainer, bytes, offset, size);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   665
        return startOffset;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   666
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   667
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   668
    public void addMetadataGotEntry(int offset) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   669
        metadataGotContainer.appendLong(offset);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   670
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   671
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   672
    public int addMetaspaceName(String name) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   673
        Integer value = metaspaceNames.get(name);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   674
        if (value != null) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   675
            return value.intValue();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   676
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   677
        // Get the current length of the stubsNameContainer
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   678
        // align on 8-byte boundary
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   679
        int nameOffset = alignUp(metaspaceNamesContainer, 8);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   680
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   681
        try {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   682
            // Add the name of the symbol to the .stubs.names section
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   683
            // Modify them to sequence of utf8 strings with length:
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   684
            // "<u2_size>Ljava/lang/ThreadGroup;<u2_size>addUnstarted<u2_size>()V"
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   685
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   686
            DataOutputStream out = new DataOutputStream(bout);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   687
            int len = name.length();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   688
            if (name.startsWith("Stub")) { // Stub
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   689
                out.writeUTF(name);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   690
            } else { // Method or Klass
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   691
                int parenthesesIndex = name.lastIndexOf('(', len - 1);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   692
                if (parenthesesIndex > 0) {  // Method name
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   693
                    int dotIndex = name.lastIndexOf('.', parenthesesIndex - 1);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   694
                    assert dotIndex > 0 : "method's full name should have '.' : " + name;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   695
                    String klassName = name.substring(0, dotIndex);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   696
                    out.writeUTF(klassName);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   697
                    String methodName = name.substring(dotIndex + 1, parenthesesIndex);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   698
                    out.writeUTF(methodName);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   699
                    String signature = name.substring(parenthesesIndex, len);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   700
                    out.writeUTF(signature);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   701
                } else {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   702
                    out.writeUTF(name); // Klass
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   703
                }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   704
            }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   705
            out.writeShort(0); // Terminate by 0.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   706
            byte[] b = bout.toByteArray();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   707
            metaspaceNamesContainer.appendBytes(b, 0, b.length);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   708
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   709
            metaspaceNames.put(name, nameOffset);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   710
            return nameOffset;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   711
        } catch (IOException e) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   712
            throw new InternalError("Failed to append bytes to stubs sections", e);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   713
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   714
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   715
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   716
    /**
47084
630d326a3d15 8186850: Update Graal
iveresov
parents: 46949
diff changeset
   717
     * Add oop symbol by as follows. Extend the oop.got section with another slot for the VM to
630d326a3d15 8186850: Update Graal
iveresov
parents: 46949
diff changeset
   718
     * patch.
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   719
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   720
     * @param oopName name of the oop symbol
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   721
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   722
    public Integer addOopSymbol(String oopName) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   723
        Integer oopGotOffset = getStringOffset(oopName);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   724
        if (oopGotOffset != null) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   725
            return oopGotOffset;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   726
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   727
        return newOopSymbol(oopName);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   728
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   729
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   730
    private Integer newOopSymbol(String oopName) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   731
        // Reference to String resolution (ldc).
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   732
        int offset = oopGotContainer.getByteStreamSize();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   733
        String gotName = "got.ldc." + offset;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   734
        Symbol relocationSymbol = oopGotContainer.createGotSymbol(gotName);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   735
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   736
        if (offset != relocationSymbol.getOffset()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   737
            throw new InternalError("offset must equal! (" + offset + " vs " + relocationSymbol.getOffset());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   738
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   739
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   740
        addStringOffset(oopName, relocationSymbol.getOffset());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   741
        return relocationSymbol.getOffset();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   742
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   743
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   744
    public int addCountersSymbol(String metaspaceName) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   745
        String gotName = "got." + metaspaceName;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   746
        Symbol relocationSymbol = getGotSymbol(gotName);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   747
        int metaspaceOffset = -1;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   748
        if (relocationSymbol == null) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   749
            // Add slots when asked in the .metaspace.got section:
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   750
            countersGotContainer.createGotSymbol(gotName);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   751
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   752
        return metaspaceOffset;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   753
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   754
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   755
    public Symbol getGotSymbol(String name) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   756
        assert name.startsWith("got.");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   757
        return symbolTable.get(name);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   758
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   759
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   760
    /**
47084
630d326a3d15 8186850: Update Graal
iveresov
parents: 46949
diff changeset
   761
     * Add klass symbol by as follows. - Adding the symbol name to the metaspace.names section - Add
630d326a3d15 8186850: Update Graal
iveresov
parents: 46949
diff changeset
   762
     * the offset of the name in metaspace.names to metaspace.offsets - Extend the klasses.got
630d326a3d15 8186850: Update Graal
iveresov
parents: 46949
diff changeset
   763
     * section with another slot for the VM to patch
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   764
     *
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   765
     * @param klassName name of the metaspace symbol
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   766
     * @return the got offset in the klasses.got of the metaspace symbol
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   767
     */
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   768
    public int addTwoSlotKlassSymbol(String klassName) {
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   769
        String gotName = "got." + klassName;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   770
        Symbol previous = getGotSymbol(gotName);
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   771
        assert previous == null : "should be called only once for: " + klassName;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   772
        // Add slots when asked in the .metaspace.got section:
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   773
        // First slot
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   774
        String gotInitName = "got.init." + klassName;
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   775
        GotSymbol slot1Symbol = klassesGotContainer.createGotSymbol(gotInitName);
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   776
        GotSymbol slot2Symbol = klassesGotContainer.createGotSymbol(gotName);
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   777
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   778
        slot1Symbol.getIndex(); // check alignment and ignore result
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   779
        // Get the index (offset/8) to the got in the .metaspace.got section
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   780
        return slot2Symbol.getIndex();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   781
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   782
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   783
    public static int addMethodsCount(int count, ReadOnlyDataContainer container) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   784
        return appendInt(count, container);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   785
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   786
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   787
    private static int appendInt(int count, ReadOnlyDataContainer container) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   788
        int offset = container.getByteStreamSize();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   789
        container.appendInt(count);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   790
        return offset;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   791
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   792
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   793
    /**
46260
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   794
     * Add constant data as follows. - Adding the data to the meth.constdata section
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   795
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   796
     * @param data
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   797
     * @param alignment
46260
5de61384fba6 8172670: AOT Platform Support for Windows and Mac OS X x64
bobv
parents: 42650
diff changeset
   798
     * @return the offset in the meth.constdata of the data
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   799
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   800
    public int addConstantData(byte[] data, int alignment) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   801
        // Get the current length of the metaspaceNameContainer
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   802
        int constantDataOffset = alignUp(constantDataContainer, alignment);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   803
        constantDataContainer.appendBytes(data, 0, data.length);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   804
        alignUp(constantDataContainer, alignment); // Post alignment
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   805
        return constantDataOffset;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   806
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   807
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   808
    public static int alignUp(ByteContainer container, int alignment) {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   809
        if (Integer.bitCount(alignment) != 1) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   810
            throw new IllegalArgumentException("Must be a power of 2");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   811
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   812
        int offset = container.getByteStreamSize();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   813
        int aligned = (offset + (alignment - 1)) & -alignment;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   814
        if (aligned < offset || (aligned & (alignment - 1)) != 0) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   815
            throw new RuntimeException("Error aligning: " + offset + " -> " + aligned);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   816
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   817
        if (aligned != offset) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   818
            int nullArraySz = aligned - offset;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   819
            byte[] nullArray = new byte[nullArraySz];
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   820
            container.appendBytes(nullArray, 0, nullArraySz);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   821
            offset = aligned;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   822
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   823
        return offset;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   824
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   825
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   826
    public void addCodeSegments(int start, int end) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   827
        assert (start % codeSegmentSize) == 0 : "not aligned code";
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   828
        int currentOffset = codeSegmentsContainer.getByteStreamSize();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   829
        int offset = start / codeSegmentSize;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   830
        int emptySize = offset - currentOffset;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   831
        // add empty segments if needed
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   832
        if (emptySize > 0) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   833
            byte[] emptyArray = new byte[emptySize];
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   834
            for (int i = 0; i < emptySize; i++) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   835
                emptyArray[i] = (byte) 0xff;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   836
            }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   837
            appendBytes(codeSegmentsContainer, emptyArray, 0, emptySize);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   838
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   839
        int alignedEnd = (end + (codeSegmentSize - 1)) & -codeSegmentSize;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   840
        int segmentsCount = (alignedEnd / codeSegmentSize) - offset;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   841
        byte[] segments = new byte[segmentsCount];
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   842
        int idx = 0;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   843
        for (int i = 0; i < segmentsCount; i++) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   844
            segments[i] = (byte) idx;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   845
            idx = (idx == 0xfe) ? 1 : (idx + 1);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   846
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   847
        appendBytes(codeSegmentsContainer, segments, 0, segmentsCount);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   848
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   849
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   850
    public ByteContainer getExtLinkageGOTContainer() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   851
        return extLinkageGOTContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   852
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   853
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   854
    public ReadOnlyDataContainer getMethodMetadataContainer() {
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   855
        return methodMetadataContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   856
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   857
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   858
    public ReadOnlyDataContainer getMetaspaceNamesContainer() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   859
        return metaspaceNamesContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   860
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   861
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   862
    public ReadOnlyDataContainer getMethodsOffsetsContainer() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   863
        return methodsOffsetsContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   864
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   865
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   866
    public ReadOnlyDataContainer getKlassesOffsetsContainer() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   867
        return klassesOffsetsContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   868
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   869
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   870
    public ReadOnlyDataContainer getKlassesDependenciesContainer() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   871
        return klassesDependenciesContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   872
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   873
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   874
    public ReadOnlyDataContainer getStubsOffsetsContainer() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   875
        return stubsOffsetsContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   876
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   877
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   878
    public ReadOnlyDataContainer getCodeSegmentsContainer() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   879
        return codeSegmentsContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   880
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   881
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   882
    public ReadOnlyDataContainer getConstantDataContainer() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   883
        return constantDataContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   884
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   885
46949
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   886
    public ByteContainer getKlassesGotContainer() {
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   887
        return klassesGotContainer;
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   888
    }
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   889
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   890
    public ByteContainer getCountersGotContainer() {
44ccdba2d72e 8186453: [AOT] refactor AOT tool code
kvn
parents: 46556
diff changeset
   891
        return countersGotContainer;
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   892
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   893
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   894
    public ByteContainer getMetadataGotContainer() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   895
        return metadataGotContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   896
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   897
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   898
    public ByteContainer getMethodStateContainer() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   899
        return methodStateContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   900
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   901
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   902
    public ByteContainer getOopGotContainer() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   903
        return oopGotContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   904
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   905
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   906
    public CodeContainer getCodeContainer() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   907
        return codeContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   908
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   909
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   910
    public ReadOnlyDataContainer getConfigContainer() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   911
        return configContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   912
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   913
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   914
    public Map<Symbol, Relocation> getUniqueRelocationTable() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   915
        return uniqueRelocationTable;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   916
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   917
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   918
    public HeaderContainer getHeaderContainer() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   919
        return headerContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   920
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   921
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   922
}