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