author | kvn |
Sun, 11 Dec 2016 19:07:04 -0800 | |
changeset 42650 | 1f304d0c888b |
parent 41697 | 94ef14db8a20 |
child 42861 | 1d4dfdf4390b |
permissions | -rw-r--r-- |
33160 | 1 |
/* |
35582
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35123
diff
changeset
|
2 |
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. |
33160 | 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 |
#ifndef SHARE_VM_JVMCI_JVMCI_CODE_INSTALLER_HPP |
|
25 |
#define SHARE_VM_JVMCI_JVMCI_CODE_INSTALLER_HPP |
|
26 |
||
27 |
#include "jvmci/jvmciCompiler.hpp" |
|
28 |
#include "jvmci/jvmciEnv.hpp" |
|
29 |
#include "code/nativeInst.hpp" |
|
30 |
||
31 |
class RelocBuffer : public StackObj { |
|
32 |
enum { stack_size = 1024 }; |
|
33 |
public: |
|
34 |
RelocBuffer() : _size(0), _buffer(0) {} |
|
35 |
~RelocBuffer(); |
|
36 |
void ensure_size(size_t bytes); |
|
37 |
void set_size(size_t bytes); |
|
38 |
address begin() const; |
|
39 |
size_t size() const { return _size; } |
|
40 |
private: |
|
41 |
size_t _size; |
|
42 |
char _static_buffer[stack_size]; |
|
43 |
char *_buffer; |
|
44 |
}; |
|
45 |
||
42650 | 46 |
class AOTOopRecorder : public OopRecorder { |
47 |
public: |
|
48 |
AOTOopRecorder(Arena* arena = NULL, bool deduplicate = false); |
|
49 |
||
50 |
virtual int find_index(Metadata* h); |
|
51 |
virtual int find_index(jobject h); |
|
52 |
int nr_meta_strings() const; |
|
53 |
const char* meta_element(int pos) const; |
|
54 |
||
55 |
private: |
|
56 |
void record_meta_string(const char* name, int index); |
|
57 |
||
58 |
GrowableArray<const char*>* _meta_strings; |
|
59 |
}; |
|
60 |
||
33160 | 61 |
class CodeMetadata { |
62 |
public: |
|
63 |
CodeMetadata() {} |
|
64 |
||
65 |
CodeBlob* get_code_blob() const { return _cb; } |
|
66 |
||
67 |
PcDesc* get_pc_desc() const { return _pc_desc; } |
|
68 |
int get_nr_pc_desc() const { return _nr_pc_desc; } |
|
69 |
||
70 |
u_char* get_scopes_desc() const { return _scopes_desc; } |
|
71 |
int get_scopes_size() const { return _nr_scopes_desc; } |
|
72 |
||
73 |
RelocBuffer* get_reloc_buffer() { return &_reloc_buffer; } |
|
74 |
||
42650 | 75 |
AOTOopRecorder* get_oop_recorder() { return _oop_recorder; } |
76 |
||
33160 | 77 |
ExceptionHandlerTable* get_exception_table() { return _exception_table; } |
78 |
||
79 |
void set_pc_desc(PcDesc* desc, int count) { |
|
80 |
_pc_desc = desc; |
|
81 |
_nr_pc_desc = count; |
|
82 |
} |
|
83 |
||
84 |
void set_scopes(u_char* scopes, int size) { |
|
85 |
_scopes_desc = scopes; |
|
86 |
_nr_scopes_desc = size; |
|
87 |
} |
|
88 |
||
42650 | 89 |
void set_oop_recorder(AOTOopRecorder* recorder) { |
90 |
_oop_recorder = recorder; |
|
91 |
} |
|
92 |
||
33160 | 93 |
void set_exception_table(ExceptionHandlerTable* table) { |
94 |
_exception_table = table; |
|
95 |
} |
|
96 |
||
97 |
private: |
|
98 |
CodeBlob* _cb; |
|
99 |
PcDesc* _pc_desc; |
|
100 |
int _nr_pc_desc; |
|
101 |
||
102 |
u_char* _scopes_desc; |
|
103 |
int _nr_scopes_desc; |
|
104 |
||
105 |
RelocBuffer _reloc_buffer; |
|
42650 | 106 |
AOTOopRecorder* _oop_recorder; |
33160 | 107 |
ExceptionHandlerTable* _exception_table; |
108 |
}; |
|
109 |
||
110 |
/* |
|
111 |
* This class handles the conversion from a InstalledCode to a CodeBlob or an nmethod. |
|
112 |
*/ |
|
113 |
class CodeInstaller : public StackObj { |
|
35123
b0b89d83bcf5
8134994: use separate VMStructs databases for SA and JVMCI
twisti
parents:
34502
diff
changeset
|
114 |
friend class JVMCIVMStructs; |
33160 | 115 |
private: |
116 |
enum MarkId { |
|
42650 | 117 |
VERIFIED_ENTRY = 1, |
118 |
UNVERIFIED_ENTRY = 2, |
|
119 |
OSR_ENTRY = 3, |
|
120 |
EXCEPTION_HANDLER_ENTRY = 4, |
|
121 |
DEOPT_HANDLER_ENTRY = 5, |
|
122 |
INVOKEINTERFACE = 6, |
|
123 |
INVOKEVIRTUAL = 7, |
|
124 |
INVOKESTATIC = 8, |
|
125 |
INVOKESPECIAL = 9, |
|
126 |
INLINE_INVOKE = 10, |
|
127 |
POLL_NEAR = 11, |
|
128 |
POLL_RETURN_NEAR = 12, |
|
129 |
POLL_FAR = 13, |
|
130 |
POLL_RETURN_FAR = 14, |
|
131 |
CARD_TABLE_ADDRESS = 15, |
|
132 |
CARD_TABLE_SHIFT = 16, |
|
133 |
HEAP_TOP_ADDRESS = 17, |
|
134 |
HEAP_END_ADDRESS = 18, |
|
135 |
NARROW_KLASS_BASE_ADDRESS = 19, |
|
136 |
CRC_TABLE_ADDRESS = 20, |
|
137 |
LOG_OF_HEAP_REGION_GRAIN_BYTES = 21, |
|
138 |
INLINE_CONTIGUOUS_ALLOCATION_SUPPORTED = 22, |
|
139 |
INVOKE_INVALID = -1 |
|
33160 | 140 |
}; |
141 |
||
142 |
Arena _arena; |
|
143 |
||
144 |
jobject _data_section_handle; |
|
145 |
jobject _data_section_patches_handle; |
|
146 |
jobject _sites_handle; |
|
147 |
CodeOffsets _offsets; |
|
148 |
||
149 |
jobject _code_handle; |
|
150 |
jint _code_size; |
|
151 |
jint _total_frame_size; |
|
35823
59a847ec6ee3
8146608: [JVMCI] DebugInfo Tests on DeoptimizeALot runs fails in assert(_pc == *pc_addr || pc == *pc_addr) frame::patch_pc() /frame_x86.cpp:285
rschatz
parents:
35582
diff
changeset
|
152 |
jint _orig_pc_offset; |
33160 | 153 |
jint _parameter_count; |
154 |
jint _constants_size; |
|
155 |
#ifndef PRODUCT |
|
156 |
jobject _comments_handle; |
|
157 |
#endif |
|
158 |
||
159 |
bool _has_wide_vector; |
|
160 |
jobject _word_kind_handle; |
|
161 |
||
162 |
MarkId _next_call_type; |
|
163 |
address _invoke_mark_pc; |
|
164 |
||
165 |
CodeSection* _instructions; |
|
166 |
CodeSection* _constants; |
|
167 |
||
168 |
OopRecorder* _oop_recorder; |
|
169 |
DebugInformationRecorder* _debug_recorder; |
|
170 |
Dependencies* _dependencies; |
|
171 |
ExceptionHandlerTable _exception_handler_table; |
|
172 |
||
42650 | 173 |
bool _immutable_pic_compilation; // Installer is called for Immutable PIC compilation. |
174 |
||
33160 | 175 |
static ConstantOopWriteValue* _oop_null_scope_value; |
176 |
static ConstantIntValue* _int_m1_scope_value; |
|
177 |
static ConstantIntValue* _int_0_scope_value; |
|
178 |
static ConstantIntValue* _int_1_scope_value; |
|
179 |
static ConstantIntValue* _int_2_scope_value; |
|
180 |
static LocationValue* _illegal_value; |
|
181 |
||
34153
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
182 |
jint pd_next_offset(NativeInstruction* inst, jint pc_offset, Handle method, TRAPS); |
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
183 |
void pd_patch_OopConstant(int pc_offset, Handle constant, TRAPS); |
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
184 |
void pd_patch_MetaspaceConstant(int pc_offset, Handle constant, TRAPS); |
36063
96e86c7f8fec
8149689: [JVMCI] CodeInstaller::pd_patch_DataSectionReference should be able to throw exceptions
twisti
parents:
35823
diff
changeset
|
185 |
void pd_patch_DataSectionReference(int pc_offset, int data_offset, TRAPS); |
34153
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
186 |
void pd_relocate_ForeignCall(NativeInstruction* inst, jlong foreign_call_destination, TRAPS); |
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
187 |
void pd_relocate_JavaMethod(Handle method, jint pc_offset, TRAPS); |
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
188 |
void pd_relocate_poll(address pc, jint mark, TRAPS); |
33160 | 189 |
|
190 |
objArrayOop sites() { return (objArrayOop) JNIHandles::resolve(_sites_handle); } |
|
191 |
arrayOop code() { return (arrayOop) JNIHandles::resolve(_code_handle); } |
|
192 |
arrayOop data_section() { return (arrayOop) JNIHandles::resolve(_data_section_handle); } |
|
193 |
objArrayOop data_section_patches() { return (objArrayOop) JNIHandles::resolve(_data_section_patches_handle); } |
|
194 |
#ifndef PRODUCT |
|
195 |
objArrayOop comments() { return (objArrayOop) JNIHandles::resolve(_comments_handle); } |
|
196 |
#endif |
|
197 |
||
198 |
oop word_kind() { return (oop) JNIHandles::resolve(_word_kind_handle); } |
|
199 |
||
200 |
public: |
|
33632 | 201 |
|
42650 | 202 |
CodeInstaller(bool immutable_pic_compilation) : _arena(mtCompiler), _immutable_pic_compilation(immutable_pic_compilation) {} |
33160 | 203 |
|
34165 | 204 |
JVMCIEnv::CodeInstallResult gather_metadata(Handle target, Handle compiled_code, CodeMetadata& metadata, TRAPS); |
205 |
JVMCIEnv::CodeInstallResult install(JVMCICompiler* compiler, Handle target, Handle compiled_code, CodeBlob*& cb, Handle installed_code, Handle speculation_log, TRAPS); |
|
33160 | 206 |
|
207 |
static address runtime_call_target_address(oop runtime_call); |
|
34153
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
208 |
static VMReg get_hotspot_reg(jint jvmciRegisterNumber, TRAPS); |
33160 | 209 |
static bool is_general_purpose_reg(VMReg hotspotRegister); |
210 |
||
211 |
const OopMapSet* oopMapSet() const { return _debug_recorder->_oopmaps; } |
|
212 |
||
213 |
protected: |
|
34153
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
214 |
Location::Type get_oop_type(Handle value); |
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
215 |
ScopeValue* get_scope_value(Handle value, BasicType type, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, TRAPS); |
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
216 |
MonitorValue* get_monitor_value(Handle value, GrowableArray<ScopeValue*>* objects, TRAPS); |
33160 | 217 |
|
41697
94ef14db8a20
8166869: [JVMCI] record metadata relocations for metadata references
never
parents:
36842
diff
changeset
|
218 |
void* record_metadata_reference(CodeSection* section, address dest, Handle constant, TRAPS); |
33632 | 219 |
#ifdef _LP64 |
41697
94ef14db8a20
8166869: [JVMCI] record metadata relocations for metadata references
never
parents:
36842
diff
changeset
|
220 |
narrowKlass record_narrow_metadata_reference(CodeSection* section, address dest, Handle constant, TRAPS); |
33632 | 221 |
#endif |
222 |
||
35582
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35123
diff
changeset
|
223 |
// extract the fields of the HotSpotCompiledCode |
34153
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
224 |
void initialize_fields(oop target, oop target_method, TRAPS); |
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
225 |
void initialize_dependencies(oop target_method, OopRecorder* oop_recorder, TRAPS); |
33160 | 226 |
|
34153
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
227 |
int estimate_stubs_size(TRAPS); |
33160 | 228 |
|
229 |
// perform data and call relocation on the CodeBuffer |
|
34153
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
230 |
JVMCIEnv::CodeInstallResult initialize_buffer(CodeBuffer& buffer, TRAPS); |
33160 | 231 |
|
232 |
void assumption_NoFinalizableSubclass(Handle assumption); |
|
233 |
void assumption_ConcreteSubtype(Handle assumption); |
|
234 |
void assumption_LeafType(Handle assumption); |
|
235 |
void assumption_ConcreteMethod(Handle assumption); |
|
236 |
void assumption_CallSiteTargetValue(Handle assumption); |
|
237 |
||
34153
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
238 |
void site_Safepoint(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS); |
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
239 |
void site_Infopoint(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS); |
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
240 |
void site_Call(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS); |
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
241 |
void site_DataPatch(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS); |
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
242 |
void site_Mark(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS); |
35582
c32a0cc19877
8147599: [JVMCI] simplify code installation interface
rschatz
parents:
35123
diff
changeset
|
243 |
void site_ExceptionHandler(jint pc_offset, Handle site); |
33160 | 244 |
|
34153
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
245 |
OopMap* create_oop_map(Handle debug_info, TRAPS); |
33160 | 246 |
|
34502
1cfcb971cb17
8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents:
34165
diff
changeset
|
247 |
/** |
1cfcb971cb17
8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents:
34165
diff
changeset
|
248 |
* Specifies the level of detail to record for a scope. |
1cfcb971cb17
8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents:
34165
diff
changeset
|
249 |
*/ |
1cfcb971cb17
8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents:
34165
diff
changeset
|
250 |
enum ScopeMode { |
1cfcb971cb17
8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents:
34165
diff
changeset
|
251 |
// Only record a method and BCI |
1cfcb971cb17
8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents:
34165
diff
changeset
|
252 |
BytecodePosition, |
1cfcb971cb17
8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents:
34165
diff
changeset
|
253 |
// Record a method, bci and JVM frame state |
1cfcb971cb17
8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents:
34165
diff
changeset
|
254 |
FullFrame |
1cfcb971cb17
8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents:
34165
diff
changeset
|
255 |
}; |
1cfcb971cb17
8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents:
34165
diff
changeset
|
256 |
|
1cfcb971cb17
8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents:
34165
diff
changeset
|
257 |
void record_scope(jint pc_offset, Handle debug_info, ScopeMode scope_mode, TRAPS); |
1cfcb971cb17
8143730: [JVMCI] infopoint recording is too restrictive
dnsimon
parents:
34165
diff
changeset
|
258 |
void record_scope(jint pc_offset, Handle position, ScopeMode scope_mode, GrowableArray<ScopeValue*>* objects, TRAPS); |
34153
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
259 |
void record_object_value(ObjectValue* sv, Handle value, GrowableArray<ScopeValue*>* objects, TRAPS); |
33160 | 260 |
|
34153
cbcfa2a6fe0b
8139589: [JVMCI] throw exceptions in faulty code installation operations
twisti
parents:
33632
diff
changeset
|
261 |
GrowableArray<ScopeValue*>* record_virtual_objects(Handle debug_info, TRAPS); |
33160 | 262 |
|
263 |
int estimateStubSpace(int static_call_stubs); |
|
264 |
}; |
|
265 |
||
266 |
/** |
|
267 |
* Gets the Method metaspace object from a HotSpotResolvedJavaMethodImpl Java object. |
|
268 |
*/ |
|
269 |
Method* getMethodFromHotSpotMethod(oop hotspot_method); |
|
270 |
||
271 |
||
272 |
||
273 |
#endif // SHARE_VM_JVMCI_JVMCI_CODE_INSTALLER_HPP |