Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/code/codeBlob.hpp
32285 views
1
/*
2
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
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
25
#ifndef SHARE_VM_CODE_CODEBLOB_HPP
26
#define SHARE_VM_CODE_CODEBLOB_HPP
27
28
#include "asm/codeBuffer.hpp"
29
#include "compiler/oopMap.hpp"
30
#include "runtime/frame.hpp"
31
#include "runtime/handles.hpp"
32
33
// CodeBlob Types
34
// Used in the CodeCache to assign CodeBlobs to different CodeHeaps
35
struct CodeBlobType {
36
enum {
37
All = 0, // All types (No code cache segmentation)
38
NumTypes = 1 // Number of CodeBlobTypes
39
};
40
};
41
42
// CodeBlob - superclass for all entries in the CodeCache.
43
//
44
// Suptypes are:
45
// nmethod : Compiled Java methods (include method that calls to native code)
46
// RuntimeStub : Call to VM runtime methods
47
// DeoptimizationBlob : Used for deoptimizatation
48
// ExceptionBlob : Used for stack unrolling
49
// SafepointBlob : Used to handle illegal instruction exceptions
50
//
51
//
52
// Layout:
53
// - header
54
// - relocation
55
// - content space
56
// - instruction space
57
// - data space
58
class DeoptimizationBlob;
59
60
class CodeBlob VALUE_OBJ_CLASS_SPEC {
61
62
friend class VMStructs;
63
64
private:
65
const char* _name;
66
int _size; // total size of CodeBlob in bytes
67
int _header_size; // size of header (depends on subclass)
68
int _relocation_size; // size of relocation
69
int _content_offset; // offset to where content region begins (this includes consts, insts, stubs)
70
int _code_offset; // offset to where instructions region begins (this includes insts, stubs)
71
int _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have
72
// not finished setting up their frame. Beware of pc's in
73
// that range. There is a similar range(s) on returns
74
// which we don't detect.
75
int _data_offset; // offset to where data region begins
76
int _frame_size; // size of stack frame
77
OopMapSet* _oop_maps; // OopMap for this CodeBlob
78
CodeStrings _strings;
79
80
public:
81
// Returns the space needed for CodeBlob
82
static unsigned int allocation_size(CodeBuffer* cb, int header_size);
83
static unsigned int align_code_offset(int offset);
84
85
// Creation
86
// a) simple CodeBlob
87
// frame_complete is the offset from the beginning of the instructions
88
// to where the frame setup (from stackwalk viewpoint) is complete.
89
CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size);
90
91
// b) full CodeBlob
92
CodeBlob(
93
const char* name,
94
CodeBuffer* cb,
95
int header_size,
96
int size,
97
int frame_complete,
98
int frame_size,
99
OopMapSet* oop_maps
100
);
101
102
// Deletion
103
void flush();
104
105
// Typing
106
virtual bool is_buffer_blob() const { return false; }
107
virtual bool is_nmethod() const { return false; }
108
virtual bool is_runtime_stub() const { return false; }
109
virtual bool is_deoptimization_stub() const { return false; }
110
virtual bool is_uncommon_trap_stub() const { return false; }
111
virtual bool is_exception_stub() const { return false; }
112
virtual bool is_safepoint_stub() const { return false; }
113
virtual bool is_adapter_blob() const { return false; }
114
virtual bool is_vtable_blob() const { return false; }
115
virtual bool is_method_handles_adapter_blob() const { return false; }
116
117
virtual bool is_compiled_by_c2() const { return false; }
118
virtual bool is_compiled_by_c1() const { return false; }
119
120
// Casting
121
nmethod* as_nmethod_or_null() { return is_nmethod() ? (nmethod*) this : NULL; }
122
123
// Boundaries
124
address header_begin() const { return (address) this; }
125
address header_end() const { return ((address) this) + _header_size; };
126
relocInfo* relocation_begin() const { return (relocInfo*) header_end(); };
127
relocInfo* relocation_end() const { return (relocInfo*)(header_end() + _relocation_size); }
128
address content_begin() const { return (address) header_begin() + _content_offset; }
129
address content_end() const { return (address) header_begin() + _data_offset; }
130
address code_begin() const { return (address) header_begin() + _code_offset; }
131
address code_end() const { return (address) header_begin() + _data_offset; }
132
address data_begin() const { return (address) header_begin() + _data_offset; }
133
address data_end() const { return (address) header_begin() + _size; }
134
135
// Offsets
136
int relocation_offset() const { return _header_size; }
137
int content_offset() const { return _content_offset; }
138
int code_offset() const { return _code_offset; }
139
int data_offset() const { return _data_offset; }
140
141
// Sizes
142
int size() const { return _size; }
143
int header_size() const { return _header_size; }
144
int relocation_size() const { return (address) relocation_end() - (address) relocation_begin(); }
145
int content_size() const { return content_end() - content_begin(); }
146
int code_size() const { return code_end() - code_begin(); }
147
int data_size() const { return data_end() - data_begin(); }
148
149
// Containment
150
bool blob_contains(address addr) const { return header_begin() <= addr && addr < data_end(); }
151
bool relocation_contains(relocInfo* addr) const{ return relocation_begin() <= addr && addr < relocation_end(); }
152
bool content_contains(address addr) const { return content_begin() <= addr && addr < content_end(); }
153
bool code_contains(address addr) const { return code_begin() <= addr && addr < code_end(); }
154
bool data_contains(address addr) const { return data_begin() <= addr && addr < data_end(); }
155
bool contains(address addr) const { return content_contains(addr); }
156
bool is_frame_complete_at(address addr) const { return code_contains(addr) &&
157
addr >= code_begin() + _frame_complete_offset; }
158
159
// CodeCache support: really only used by the nmethods, but in order to get
160
// asserts and certain bookkeeping to work in the CodeCache they are defined
161
// virtual here.
162
virtual bool is_zombie() const { return false; }
163
virtual bool is_locked_by_vm() const { return false; }
164
165
virtual bool is_unloaded() const { return false; }
166
virtual bool is_not_entrant() const { return false; }
167
168
// GC support
169
virtual bool is_alive() const = 0;
170
171
// OopMap for frame
172
OopMapSet* oop_maps() const { return _oop_maps; }
173
void set_oop_maps(OopMapSet* p);
174
OopMap* oop_map_for_return_address(address return_address);
175
virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { ShouldNotReachHere(); }
176
177
// Frame support
178
int frame_size() const { return _frame_size; }
179
void set_frame_size(int size) { _frame_size = size; }
180
181
// Returns true, if the next frame is responsible for GC'ing oops passed as arguments
182
virtual bool caller_must_gc_arguments(JavaThread* thread) const { return false; }
183
184
// Naming
185
const char* name() const { return _name; }
186
void set_name(const char* name) { _name = name; }
187
188
// Debugging
189
virtual void verify();
190
void print() const { print_on(tty); }
191
virtual void print_on(outputStream* st) const;
192
virtual void print_value_on(outputStream* st) const;
193
void print_code();
194
195
// Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService.
196
static void trace_new_stub(CodeBlob* blob, const char* name1, const char* name2 = "");
197
198
// Print the comment associated with offset on stream, if there is one
199
virtual void print_block_comment(outputStream* stream, address block_begin) const {
200
intptr_t offset = (intptr_t)(block_begin - code_begin());
201
_strings.print_block_comment(stream, offset);
202
}
203
204
// Transfer ownership of comments to this CodeBlob
205
void set_strings(CodeStrings& strings) {
206
_strings.assign(strings);
207
}
208
};
209
210
211
//----------------------------------------------------------------------------------------------------
212
// BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
213
214
class BufferBlob: public CodeBlob {
215
friend class VMStructs;
216
friend class AdapterBlob;
217
friend class VtableBlob;
218
friend class MethodHandlesAdapterBlob;
219
friend class WhiteBox;
220
221
private:
222
// Creation support
223
BufferBlob(const char* name, int size);
224
BufferBlob(const char* name, int size, CodeBuffer* cb);
225
226
void* operator new(size_t s, unsigned size, bool is_critical = false) throw();
227
228
public:
229
// Creation
230
static BufferBlob* create(const char* name, int buffer_size);
231
static BufferBlob* create(const char* name, CodeBuffer* cb);
232
233
static void free(BufferBlob* buf);
234
235
// Typing
236
virtual bool is_buffer_blob() const { return true; }
237
238
// GC/Verification support
239
void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ }
240
bool is_alive() const { return true; }
241
242
void verify();
243
void print_on(outputStream* st) const;
244
void print_value_on(outputStream* st) const;
245
};
246
247
248
//----------------------------------------------------------------------------------------------------
249
// AdapterBlob: used to hold C2I/I2C adapters
250
251
class AdapterBlob: public BufferBlob {
252
private:
253
AdapterBlob(int size, CodeBuffer* cb);
254
255
public:
256
// Creation
257
static AdapterBlob* create(CodeBuffer* cb);
258
259
// Typing
260
virtual bool is_adapter_blob() const { return true; }
261
};
262
263
//---------------------------------------------------------------------------------------------------
264
class VtableBlob: public BufferBlob {
265
private:
266
VtableBlob(const char*, int);
267
268
public:
269
// Creation
270
static VtableBlob* create(const char* name, int buffer_size);
271
272
// Typing
273
virtual bool is_vtable_blob() const { return true; }
274
};
275
276
//----------------------------------------------------------------------------------------------------
277
// MethodHandlesAdapterBlob: used to hold MethodHandles adapters
278
279
class MethodHandlesAdapterBlob: public BufferBlob {
280
private:
281
MethodHandlesAdapterBlob(int size) : BufferBlob("MethodHandles adapters", size) {}
282
283
public:
284
// Creation
285
static MethodHandlesAdapterBlob* create(int buffer_size);
286
287
// Typing
288
virtual bool is_method_handles_adapter_blob() const { return true; }
289
};
290
291
292
//----------------------------------------------------------------------------------------------------
293
// RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
294
295
class RuntimeStub: public CodeBlob {
296
friend class VMStructs;
297
private:
298
bool _caller_must_gc_arguments;
299
300
// Creation support
301
RuntimeStub(
302
const char* name,
303
CodeBuffer* cb,
304
int size,
305
int frame_complete,
306
int frame_size,
307
OopMapSet* oop_maps,
308
bool caller_must_gc_arguments
309
);
310
311
void* operator new(size_t s, unsigned size) throw();
312
313
public:
314
// Creation
315
static RuntimeStub* new_runtime_stub(
316
const char* stub_name,
317
CodeBuffer* cb,
318
int frame_complete,
319
int frame_size,
320
OopMapSet* oop_maps,
321
bool caller_must_gc_arguments
322
);
323
324
// Typing
325
bool is_runtime_stub() const { return true; }
326
327
// GC support
328
bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; }
329
330
address entry_point() { return code_begin(); }
331
332
// GC/Verification support
333
void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* nothing to do */ }
334
bool is_alive() const { return true; }
335
336
void verify();
337
void print_on(outputStream* st) const;
338
void print_value_on(outputStream* st) const;
339
};
340
341
342
//----------------------------------------------------------------------------------------------------
343
// Super-class for all blobs that exist in only one instance. Implements default behaviour.
344
345
class SingletonBlob: public CodeBlob {
346
friend class VMStructs;
347
348
protected:
349
void* operator new(size_t s, unsigned size) throw();
350
351
public:
352
SingletonBlob(
353
const char* name,
354
CodeBuffer* cb,
355
int header_size,
356
int size,
357
int frame_size,
358
OopMapSet* oop_maps
359
)
360
: CodeBlob(name, cb, header_size, size, CodeOffsets::frame_never_safe, frame_size, oop_maps)
361
{};
362
363
address entry_point() { return code_begin(); }
364
365
bool is_alive() const { return true; }
366
367
void verify(); // does nothing
368
void print_on(outputStream* st) const;
369
void print_value_on(outputStream* st) const;
370
};
371
372
373
//----------------------------------------------------------------------------------------------------
374
// DeoptimizationBlob
375
376
class DeoptimizationBlob: public SingletonBlob {
377
friend class VMStructs;
378
private:
379
int _unpack_offset;
380
int _unpack_with_exception;
381
int _unpack_with_reexecution;
382
383
int _unpack_with_exception_in_tls;
384
385
// Creation support
386
DeoptimizationBlob(
387
CodeBuffer* cb,
388
int size,
389
OopMapSet* oop_maps,
390
int unpack_offset,
391
int unpack_with_exception_offset,
392
int unpack_with_reexecution_offset,
393
int frame_size
394
);
395
396
public:
397
// Creation
398
static DeoptimizationBlob* create(
399
CodeBuffer* cb,
400
OopMapSet* oop_maps,
401
int unpack_offset,
402
int unpack_with_exception_offset,
403
int unpack_with_reexecution_offset,
404
int frame_size
405
);
406
407
// Typing
408
bool is_deoptimization_stub() const { return true; }
409
bool exception_address_is_unpack_entry(address pc) const {
410
address unpack_pc = unpack();
411
return (pc == unpack_pc || (pc + frame::pc_return_offset) == unpack_pc);
412
}
413
414
415
416
417
// GC for args
418
void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* Nothing to do */ }
419
420
// Printing
421
void print_value_on(outputStream* st) const;
422
423
address unpack() const { return code_begin() + _unpack_offset; }
424
address unpack_with_exception() const { return code_begin() + _unpack_with_exception; }
425
address unpack_with_reexecution() const { return code_begin() + _unpack_with_reexecution; }
426
427
// Alternate entry point for C1 where the exception and issuing pc
428
// are in JavaThread::_exception_oop and JavaThread::_exception_pc
429
// instead of being in registers. This is needed because C1 doesn't
430
// model exception paths in a way that keeps these registers free so
431
// there may be live values in those registers during deopt.
432
void set_unpack_with_exception_in_tls_offset(int offset) {
433
_unpack_with_exception_in_tls = offset;
434
assert(code_contains(code_begin() + _unpack_with_exception_in_tls), "must be PC inside codeblob");
435
}
436
address unpack_with_exception_in_tls() const { return code_begin() + _unpack_with_exception_in_tls; }
437
};
438
439
440
//----------------------------------------------------------------------------------------------------
441
// UncommonTrapBlob (currently only used by Compiler 2)
442
443
#ifdef COMPILER2
444
445
class UncommonTrapBlob: public SingletonBlob {
446
friend class VMStructs;
447
private:
448
// Creation support
449
UncommonTrapBlob(
450
CodeBuffer* cb,
451
int size,
452
OopMapSet* oop_maps,
453
int frame_size
454
);
455
456
public:
457
// Creation
458
static UncommonTrapBlob* create(
459
CodeBuffer* cb,
460
OopMapSet* oop_maps,
461
int frame_size
462
);
463
464
// GC for args
465
void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* nothing to do */ }
466
467
// Typing
468
bool is_uncommon_trap_stub() const { return true; }
469
};
470
471
472
//----------------------------------------------------------------------------------------------------
473
// ExceptionBlob: used for exception unwinding in compiled code (currently only used by Compiler 2)
474
475
class ExceptionBlob: public SingletonBlob {
476
friend class VMStructs;
477
private:
478
// Creation support
479
ExceptionBlob(
480
CodeBuffer* cb,
481
int size,
482
OopMapSet* oop_maps,
483
int frame_size
484
);
485
486
public:
487
// Creation
488
static ExceptionBlob* create(
489
CodeBuffer* cb,
490
OopMapSet* oop_maps,
491
int frame_size
492
);
493
494
// GC for args
495
void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ }
496
497
// Typing
498
bool is_exception_stub() const { return true; }
499
};
500
#endif // COMPILER2
501
502
503
//----------------------------------------------------------------------------------------------------
504
// SafepointBlob: handles illegal_instruction exceptions during a safepoint
505
506
class SafepointBlob: public SingletonBlob {
507
friend class VMStructs;
508
private:
509
// Creation support
510
SafepointBlob(
511
CodeBuffer* cb,
512
int size,
513
OopMapSet* oop_maps,
514
int frame_size
515
);
516
517
public:
518
// Creation
519
static SafepointBlob* create(
520
CodeBuffer* cb,
521
OopMapSet* oop_maps,
522
int frame_size
523
);
524
525
// GC for args
526
void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) { /* nothing to do */ }
527
528
// Typing
529
bool is_safepoint_stub() const { return true; }
530
};
531
532
#endif // SHARE_VM_CODE_CODEBLOB_HPP
533
534