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