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
46 class CodeMetadata {
47 public:
48 CodeMetadata() {}
49
50 CodeBlob* get_code_blob() const { return _cb; }
51
52 PcDesc* get_pc_desc() const { return _pc_desc; }
53 int get_nr_pc_desc() const { return _nr_pc_desc; }
54
55 u_char* get_scopes_desc() const { return _scopes_desc; }
56 int get_scopes_size() const { return _nr_scopes_desc; }
57
58 RelocBuffer* get_reloc_buffer() { return &_reloc_buffer; }
59
60 ExceptionHandlerTable* get_exception_table() { return _exception_table; }
61
62 void set_pc_desc(PcDesc* desc, int count) {
63 _pc_desc = desc;
64 _nr_pc_desc = count;
65 }
66
67 void set_scopes(u_char* scopes, int size) {
68 _scopes_desc = scopes;
69 _nr_scopes_desc = size;
70 }
71
72 void set_exception_table(ExceptionHandlerTable* table) {
73 _exception_table = table;
74 }
75
76 private:
77 CodeBlob* _cb;
78 PcDesc* _pc_desc;
79 int _nr_pc_desc;
80
81 u_char* _scopes_desc;
82 int _nr_scopes_desc;
83
84 RelocBuffer _reloc_buffer;
85 ExceptionHandlerTable* _exception_table;
86 };
87
88 /*
89 * This class handles the conversion from a InstalledCode to a CodeBlob or an nmethod.
90 */
91 class CodeInstaller : public StackObj {
92 friend class JVMCIVMStructs;
93 private:
94 enum MarkId {
95 VERIFIED_ENTRY = 1,
96 UNVERIFIED_ENTRY = 2,
97 OSR_ENTRY = 3,
98 EXCEPTION_HANDLER_ENTRY = 4,
99 DEOPT_HANDLER_ENTRY = 5,
100 INVOKEINTERFACE = 6,
101 INVOKEVIRTUAL = 7,
102 INVOKESTATIC = 8,
103 INVOKESPECIAL = 9,
104 INLINE_INVOKE = 10,
105 POLL_NEAR = 11,
106 POLL_RETURN_NEAR = 12,
107 POLL_FAR = 13,
108 POLL_RETURN_FAR = 14,
109 CARD_TABLE_ADDRESS = 15,
110 CARD_TABLE_SHIFT = 16,
111 HEAP_TOP_ADDRESS = 17,
112 HEAP_END_ADDRESS = 18,
113 NARROW_KLASS_BASE_ADDRESS = 19,
114 CRC_TABLE_ADDRESS = 20,
115 INVOKE_INVALID = -1
116 };
117
118 Arena _arena;
119
120 jobject _data_section_handle;
121 jobject _data_section_patches_handle;
122 jobject _sites_handle;
123 CodeOffsets _offsets;
124
125 jobject _code_handle;
126 jint _code_size;
127 jint _total_frame_size;
128 jint _orig_pc_offset;
129 jint _parameter_count;
130 jint _constants_size;
131 #ifndef PRODUCT
132 jobject _comments_handle;
133 #endif
134
135 bool _has_wide_vector;
136 jobject _word_kind_handle;
137
138 MarkId _next_call_type;
139 address _invoke_mark_pc;
140
141 CodeSection* _instructions;
142 CodeSection* _constants;
143
144 OopRecorder* _oop_recorder;
145 DebugInformationRecorder* _debug_recorder;
146 Dependencies* _dependencies;
147 ExceptionHandlerTable _exception_handler_table;
148
149 static ConstantOopWriteValue* _oop_null_scope_value;
150 static ConstantIntValue* _int_m1_scope_value;
151 static ConstantIntValue* _int_0_scope_value;
152 static ConstantIntValue* _int_1_scope_value;
153 static ConstantIntValue* _int_2_scope_value;
154 static LocationValue* _illegal_value;
155
156 jint pd_next_offset(NativeInstruction* inst, jint pc_offset, Handle method, TRAPS);
157 void pd_patch_OopConstant(int pc_offset, Handle constant, TRAPS);
158 void pd_patch_MetaspaceConstant(int pc_offset, Handle constant, TRAPS);
159 void pd_patch_DataSectionReference(int pc_offset, int data_offset, TRAPS);
160 void pd_relocate_ForeignCall(NativeInstruction* inst, jlong foreign_call_destination, TRAPS);
161 void pd_relocate_JavaMethod(Handle method, jint pc_offset, TRAPS);
162 void pd_relocate_poll(address pc, jint mark, TRAPS);
163
164 objArrayOop sites() { return (objArrayOop) JNIHandles::resolve(_sites_handle); }
165 arrayOop code() { return (arrayOop) JNIHandles::resolve(_code_handle); }
166 arrayOop data_section() { return (arrayOop) JNIHandles::resolve(_data_section_handle); }
167 objArrayOop data_section_patches() { return (objArrayOop) JNIHandles::resolve(_data_section_patches_handle); }
168 #ifndef PRODUCT
169 objArrayOop comments() { return (objArrayOop) JNIHandles::resolve(_comments_handle); }
170 #endif
171
172 oop word_kind() { return (oop) JNIHandles::resolve(_word_kind_handle); }
173
174 public:
175
176 CodeInstaller() : _arena(mtCompiler) {}
177
178 JVMCIEnv::CodeInstallResult gather_metadata(Handle target, Handle compiled_code, CodeMetadata& metadata, TRAPS);
179 JVMCIEnv::CodeInstallResult install(JVMCICompiler* compiler, Handle target, Handle compiled_code, CodeBlob*& cb, Handle installed_code, Handle speculation_log, TRAPS);
180
181 static address runtime_call_target_address(oop runtime_call);
182 static VMReg get_hotspot_reg(jint jvmciRegisterNumber, TRAPS);
183 static bool is_general_purpose_reg(VMReg hotspotRegister);
184
185 const OopMapSet* oopMapSet() const { return _debug_recorder->_oopmaps; }
186
187 protected:
188 Location::Type get_oop_type(Handle value);
189 ScopeValue* get_scope_value(Handle value, BasicType type, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, TRAPS);
190 MonitorValue* get_monitor_value(Handle value, GrowableArray<ScopeValue*>* objects, TRAPS);
191
192 void* record_metadata_reference(CodeSection* section, address dest, Handle constant, TRAPS);
193 #ifdef _LP64
194 narrowKlass record_narrow_metadata_reference(CodeSection* section, address dest, Handle constant, TRAPS);
195 #endif
196
|
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
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
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
75 AOTOopRecorder* get_oop_recorder() { return _oop_recorder; }
76
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
89 void set_oop_recorder(AOTOopRecorder* recorder) {
90 _oop_recorder = recorder;
91 }
92
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;
106 AOTOopRecorder* _oop_recorder;
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 {
114 friend class JVMCIVMStructs;
115 private:
116 enum MarkId {
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 INVOKE_INVALID = -1
139 };
140
141 Arena _arena;
142
143 jobject _data_section_handle;
144 jobject _data_section_patches_handle;
145 jobject _sites_handle;
146 CodeOffsets _offsets;
147
148 jobject _code_handle;
149 jint _code_size;
150 jint _total_frame_size;
151 jint _orig_pc_offset;
152 jint _parameter_count;
153 jint _constants_size;
154 #ifndef PRODUCT
155 jobject _comments_handle;
156 #endif
157
158 bool _has_wide_vector;
159 jobject _word_kind_handle;
160
161 MarkId _next_call_type;
162 address _invoke_mark_pc;
163
164 CodeSection* _instructions;
165 CodeSection* _constants;
166
167 OopRecorder* _oop_recorder;
168 DebugInformationRecorder* _debug_recorder;
169 Dependencies* _dependencies;
170 ExceptionHandlerTable _exception_handler_table;
171
172 bool _immutable_pic_compilation; // Installer is called for Immutable PIC compilation.
173
174 static ConstantOopWriteValue* _oop_null_scope_value;
175 static ConstantIntValue* _int_m1_scope_value;
176 static ConstantIntValue* _int_0_scope_value;
177 static ConstantIntValue* _int_1_scope_value;
178 static ConstantIntValue* _int_2_scope_value;
179 static LocationValue* _illegal_value;
180
181 jint pd_next_offset(NativeInstruction* inst, jint pc_offset, Handle method, TRAPS);
182 void pd_patch_OopConstant(int pc_offset, Handle constant, TRAPS);
183 void pd_patch_MetaspaceConstant(int pc_offset, Handle constant, TRAPS);
184 void pd_patch_DataSectionReference(int pc_offset, int data_offset, TRAPS);
185 void pd_relocate_ForeignCall(NativeInstruction* inst, jlong foreign_call_destination, TRAPS);
186 void pd_relocate_JavaMethod(Handle method, jint pc_offset, TRAPS);
187 void pd_relocate_poll(address pc, jint mark, TRAPS);
188
189 objArrayOop sites() { return (objArrayOop) JNIHandles::resolve(_sites_handle); }
190 arrayOop code() { return (arrayOop) JNIHandles::resolve(_code_handle); }
191 arrayOop data_section() { return (arrayOop) JNIHandles::resolve(_data_section_handle); }
192 objArrayOop data_section_patches() { return (objArrayOop) JNIHandles::resolve(_data_section_patches_handle); }
193 #ifndef PRODUCT
194 objArrayOop comments() { return (objArrayOop) JNIHandles::resolve(_comments_handle); }
195 #endif
196
197 oop word_kind() { return (oop) JNIHandles::resolve(_word_kind_handle); }
198
199 public:
200
201 CodeInstaller(bool immutable_pic_compilation) : _arena(mtCompiler), _immutable_pic_compilation(immutable_pic_compilation) {}
202
203 JVMCIEnv::CodeInstallResult gather_metadata(Handle target, Handle compiled_code, CodeMetadata& metadata, TRAPS);
204 JVMCIEnv::CodeInstallResult install(JVMCICompiler* compiler, Handle target, Handle compiled_code, CodeBlob*& cb, Handle installed_code, Handle speculation_log, TRAPS);
205
206 static address runtime_call_target_address(oop runtime_call);
207 static VMReg get_hotspot_reg(jint jvmciRegisterNumber, TRAPS);
208 static bool is_general_purpose_reg(VMReg hotspotRegister);
209
210 const OopMapSet* oopMapSet() const { return _debug_recorder->_oopmaps; }
211
212 protected:
213 Location::Type get_oop_type(Handle value);
214 ScopeValue* get_scope_value(Handle value, BasicType type, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, TRAPS);
215 MonitorValue* get_monitor_value(Handle value, GrowableArray<ScopeValue*>* objects, TRAPS);
216
217 void* record_metadata_reference(CodeSection* section, address dest, Handle constant, TRAPS);
218 #ifdef _LP64
219 narrowKlass record_narrow_metadata_reference(CodeSection* section, address dest, Handle constant, TRAPS);
220 #endif
221
|