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.cpp
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
#include "precompiled.hpp"
26
#include "code/codeBlob.hpp"
27
#include "code/codeCache.hpp"
28
#include "code/relocInfo.hpp"
29
#include "compiler/disassembler.hpp"
30
#include "interpreter/bytecode.hpp"
31
#include "memory/allocation.inline.hpp"
32
#include "memory/heap.hpp"
33
#include "oops/oop.inline.hpp"
34
#include "prims/forte.hpp"
35
#include "runtime/handles.inline.hpp"
36
#include "runtime/interfaceSupport.hpp"
37
#include "runtime/mutexLocker.hpp"
38
#include "runtime/safepoint.hpp"
39
#include "runtime/sharedRuntime.hpp"
40
#include "runtime/vframe.hpp"
41
#include "services/memoryService.hpp"
42
#ifdef TARGET_ARCH_x86
43
# include "nativeInst_x86.hpp"
44
#endif
45
#ifdef TARGET_ARCH_aarch32
46
# include "nativeInst_aarch32.hpp"
47
#endif
48
#ifdef TARGET_ARCH_aarch64
49
# include "nativeInst_aarch64.hpp"
50
#endif
51
#ifdef TARGET_ARCH_sparc
52
# include "nativeInst_sparc.hpp"
53
#endif
54
#ifdef TARGET_ARCH_zero
55
# include "nativeInst_zero.hpp"
56
#endif
57
#ifdef TARGET_ARCH_arm
58
# include "nativeInst_arm.hpp"
59
#endif
60
#ifdef TARGET_ARCH_ppc
61
# include "nativeInst_ppc.hpp"
62
#endif
63
#ifdef COMPILER1
64
#include "c1/c1_Runtime1.hpp"
65
#endif
66
67
unsigned int CodeBlob::align_code_offset(int offset) {
68
// align the size to CodeEntryAlignment
69
return
70
((offset + (int)CodeHeap::header_size() + (CodeEntryAlignment-1)) & ~(CodeEntryAlignment-1))
71
- (int)CodeHeap::header_size();
72
}
73
74
75
// This must be consistent with the CodeBlob constructor's layout actions.
76
unsigned int CodeBlob::allocation_size(CodeBuffer* cb, int header_size) {
77
unsigned int size = header_size;
78
size += round_to(cb->total_relocation_size(), oopSize);
79
// align the size to CodeEntryAlignment
80
size = align_code_offset(size);
81
size += round_to(cb->total_content_size(), oopSize);
82
size += round_to(cb->total_oop_size(), oopSize);
83
size += round_to(cb->total_metadata_size(), oopSize);
84
return size;
85
}
86
87
88
// Creates a simple CodeBlob. Sets up the size of the different regions.
89
CodeBlob::CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size) {
90
assert(size == round_to(size, oopSize), "unaligned size");
91
assert(locs_size == round_to(locs_size, oopSize), "unaligned size");
92
assert(header_size == round_to(header_size, oopSize), "unaligned size");
93
assert(!UseRelocIndex, "no space allocated for reloc index yet");
94
95
// Note: If UseRelocIndex is enabled, there needs to be (at least) one
96
// extra word for the relocation information, containing the reloc
97
// index table length. Unfortunately, the reloc index table imple-
98
// mentation is not easily understandable and thus it is not clear
99
// what exactly the format is supposed to be. For now, we just turn
100
// off the use of this table (gri 7/6/2000).
101
102
_name = name;
103
_size = size;
104
_frame_complete_offset = frame_complete;
105
_header_size = header_size;
106
_relocation_size = locs_size;
107
_content_offset = align_code_offset(header_size + _relocation_size);
108
_code_offset = _content_offset;
109
_data_offset = size;
110
_frame_size = 0;
111
set_oop_maps(NULL);
112
}
113
114
115
// Creates a CodeBlob from a CodeBuffer. Sets up the size of the different regions,
116
// and copy code and relocation info.
117
CodeBlob::CodeBlob(
118
const char* name,
119
CodeBuffer* cb,
120
int header_size,
121
int size,
122
int frame_complete,
123
int frame_size,
124
OopMapSet* oop_maps
125
) {
126
assert(size == round_to(size, oopSize), "unaligned size");
127
assert(header_size == round_to(header_size, oopSize), "unaligned size");
128
129
_name = name;
130
_size = size;
131
_frame_complete_offset = frame_complete;
132
_header_size = header_size;
133
_relocation_size = round_to(cb->total_relocation_size(), oopSize);
134
_content_offset = align_code_offset(header_size + _relocation_size);
135
_code_offset = _content_offset + cb->total_offset_of(cb->insts());
136
_data_offset = _content_offset + round_to(cb->total_content_size(), oopSize);
137
assert(_data_offset <= size, "codeBlob is too small");
138
139
cb->copy_code_and_locs_to(this);
140
set_oop_maps(oop_maps);
141
_frame_size = frame_size;
142
#ifdef COMPILER1
143
// probably wrong for tiered
144
assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs");
145
#endif // COMPILER1
146
}
147
148
149
void CodeBlob::set_oop_maps(OopMapSet* p) {
150
// Danger Will Robinson! This method allocates a big
151
// chunk of memory, its your job to free it.
152
if (p != NULL) {
153
// We need to allocate a chunk big enough to hold the OopMapSet and all of its OopMaps
154
_oop_maps = (OopMapSet* )NEW_C_HEAP_ARRAY(unsigned char, p->heap_size(), mtCode);
155
p->copy_to((address)_oop_maps);
156
} else {
157
_oop_maps = NULL;
158
}
159
}
160
161
162
void CodeBlob::trace_new_stub(CodeBlob* stub, const char* name1, const char* name2) {
163
// Do not hold the CodeCache lock during name formatting.
164
assert(!CodeCache_lock->owned_by_self(), "release CodeCache before registering the stub");
165
166
if (stub != NULL) {
167
char stub_id[256];
168
assert(strlen(name1) + strlen(name2) < sizeof(stub_id), "");
169
jio_snprintf(stub_id, sizeof(stub_id), "%s%s", name1, name2);
170
if (PrintStubCode) {
171
ttyLocker ttyl;
172
tty->print_cr("Decoding %s " INTPTR_FORMAT, stub_id, (intptr_t) stub);
173
Disassembler::decode(stub->code_begin(), stub->code_end());
174
tty->cr();
175
}
176
Forte::register_stub(stub_id, stub->code_begin(), stub->code_end());
177
178
if (JvmtiExport::should_post_dynamic_code_generated()) {
179
const char* stub_name = name2;
180
if (name2[0] == '\0') stub_name = name1;
181
JvmtiExport::post_dynamic_code_generated(stub_name, stub->code_begin(), stub->code_end());
182
}
183
}
184
185
// Track memory usage statistic after releasing CodeCache_lock
186
MemoryService::track_code_cache_memory_usage();
187
}
188
189
190
void CodeBlob::flush() {
191
if (_oop_maps) {
192
FREE_C_HEAP_ARRAY(unsigned char, _oop_maps, mtCode);
193
_oop_maps = NULL;
194
}
195
_strings.free();
196
}
197
198
199
OopMap* CodeBlob::oop_map_for_return_address(address return_address) {
200
assert(oop_maps() != NULL, "nope");
201
return oop_maps()->find_map_at_offset((intptr_t) return_address - (intptr_t) code_begin());
202
}
203
204
void CodeBlob::print_code() {
205
HandleMark hm;
206
ResourceMark m;
207
Disassembler::decode(this, tty);
208
}
209
210
//----------------------------------------------------------------------------------------------------
211
// Implementation of BufferBlob
212
213
214
BufferBlob::BufferBlob(const char* name, int size)
215
: CodeBlob(name, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, /*locs_size:*/ 0)
216
{}
217
218
BufferBlob* BufferBlob::create(const char* name, int buffer_size) {
219
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
220
221
BufferBlob* blob = NULL;
222
unsigned int size = sizeof(BufferBlob);
223
// align the size to CodeEntryAlignment
224
size = align_code_offset(size);
225
size += round_to(buffer_size, oopSize);
226
assert(name != NULL, "must provide a name");
227
{
228
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
229
blob = new (size) BufferBlob(name, size);
230
}
231
// Track memory usage statistic after releasing CodeCache_lock
232
MemoryService::track_code_cache_memory_usage();
233
234
return blob;
235
}
236
237
238
BufferBlob::BufferBlob(const char* name, int size, CodeBuffer* cb)
239
: CodeBlob(name, cb, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, 0, NULL)
240
{}
241
242
BufferBlob* BufferBlob::create(const char* name, CodeBuffer* cb) {
243
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
244
245
BufferBlob* blob = NULL;
246
unsigned int size = allocation_size(cb, sizeof(BufferBlob));
247
assert(name != NULL, "must provide a name");
248
{
249
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
250
blob = new (size) BufferBlob(name, size, cb);
251
}
252
// Track memory usage statistic after releasing CodeCache_lock
253
MemoryService::track_code_cache_memory_usage();
254
255
return blob;
256
}
257
258
259
void* BufferBlob::operator new(size_t s, unsigned size, bool is_critical) throw() {
260
void* p = CodeCache::allocate(size, is_critical);
261
return p;
262
}
263
264
265
void BufferBlob::free( BufferBlob *blob ) {
266
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
267
blob->flush();
268
{
269
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
270
CodeCache::free((CodeBlob*)blob);
271
}
272
// Track memory usage statistic after releasing CodeCache_lock
273
MemoryService::track_code_cache_memory_usage();
274
}
275
276
277
//----------------------------------------------------------------------------------------------------
278
// Implementation of AdapterBlob
279
280
AdapterBlob::AdapterBlob(int size, CodeBuffer* cb) :
281
BufferBlob("I2C/C2I adapters", size, cb) {
282
CodeCache::commit(this);
283
}
284
285
AdapterBlob* AdapterBlob::create(CodeBuffer* cb) {
286
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
287
288
AdapterBlob* blob = NULL;
289
unsigned int size = allocation_size(cb, sizeof(AdapterBlob));
290
{
291
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
292
// The parameter 'true' indicates a critical memory allocation.
293
// This means that CodeCacheMinimumFreeSpace is used, if necessary
294
const bool is_critical = true;
295
blob = new (size, is_critical) AdapterBlob(size, cb);
296
}
297
// Track memory usage statistic after releasing CodeCache_lock
298
MemoryService::track_code_cache_memory_usage();
299
300
return blob;
301
}
302
303
VtableBlob::VtableBlob(const char* name, int size) :
304
BufferBlob(name, size) {
305
}
306
307
VtableBlob* VtableBlob::create(const char* name, int buffer_size) {
308
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
309
310
VtableBlob* blob = NULL;
311
unsigned int size = sizeof(VtableBlob);
312
// align the size to CodeEntryAlignment
313
size = align_code_offset(size);
314
size += round_to(buffer_size, oopSize);
315
assert(name != NULL, "must provide a name");
316
{
317
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
318
blob = new (size) VtableBlob(name, size);
319
}
320
// Track memory usage statistic after releasing CodeCache_lock
321
MemoryService::track_code_cache_memory_usage();
322
323
return blob;
324
}
325
326
//----------------------------------------------------------------------------------------------------
327
// Implementation of MethodHandlesAdapterBlob
328
329
MethodHandlesAdapterBlob* MethodHandlesAdapterBlob::create(int buffer_size) {
330
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
331
332
MethodHandlesAdapterBlob* blob = NULL;
333
unsigned int size = sizeof(MethodHandlesAdapterBlob);
334
// align the size to CodeEntryAlignment
335
size = align_code_offset(size);
336
size += round_to(buffer_size, oopSize);
337
{
338
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
339
// The parameter 'true' indicates a critical memory allocation.
340
// This means that CodeCacheMinimumFreeSpace is used, if necessary
341
const bool is_critical = true;
342
blob = new (size, is_critical) MethodHandlesAdapterBlob(size);
343
}
344
// Track memory usage statistic after releasing CodeCache_lock
345
MemoryService::track_code_cache_memory_usage();
346
347
return blob;
348
}
349
350
351
//----------------------------------------------------------------------------------------------------
352
// Implementation of RuntimeStub
353
354
RuntimeStub::RuntimeStub(
355
const char* name,
356
CodeBuffer* cb,
357
int size,
358
int frame_complete,
359
int frame_size,
360
OopMapSet* oop_maps,
361
bool caller_must_gc_arguments
362
)
363
: CodeBlob(name, cb, sizeof(RuntimeStub), size, frame_complete, frame_size, oop_maps)
364
{
365
_caller_must_gc_arguments = caller_must_gc_arguments;
366
}
367
368
369
RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name,
370
CodeBuffer* cb,
371
int frame_complete,
372
int frame_size,
373
OopMapSet* oop_maps,
374
bool caller_must_gc_arguments)
375
{
376
RuntimeStub* stub = NULL;
377
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
378
{
379
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
380
unsigned int size = allocation_size(cb, sizeof(RuntimeStub));
381
stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments);
382
}
383
384
trace_new_stub(stub, "RuntimeStub - ", stub_name);
385
386
return stub;
387
}
388
389
390
void* RuntimeStub::operator new(size_t s, unsigned size) throw() {
391
void* p = CodeCache::allocate(size, true);
392
if (!p) fatal("Initial size of CodeCache is too small");
393
return p;
394
}
395
396
// operator new shared by all singletons:
397
void* SingletonBlob::operator new(size_t s, unsigned size) throw() {
398
void* p = CodeCache::allocate(size, true);
399
if (!p) fatal("Initial size of CodeCache is too small");
400
return p;
401
}
402
403
404
//----------------------------------------------------------------------------------------------------
405
// Implementation of DeoptimizationBlob
406
407
DeoptimizationBlob::DeoptimizationBlob(
408
CodeBuffer* cb,
409
int size,
410
OopMapSet* oop_maps,
411
int unpack_offset,
412
int unpack_with_exception_offset,
413
int unpack_with_reexecution_offset,
414
int frame_size
415
)
416
: SingletonBlob("DeoptimizationBlob", cb, sizeof(DeoptimizationBlob), size, frame_size, oop_maps)
417
{
418
_unpack_offset = unpack_offset;
419
_unpack_with_exception = unpack_with_exception_offset;
420
_unpack_with_reexecution = unpack_with_reexecution_offset;
421
#ifdef COMPILER1
422
_unpack_with_exception_in_tls = -1;
423
#endif
424
}
425
426
427
DeoptimizationBlob* DeoptimizationBlob::create(
428
CodeBuffer* cb,
429
OopMapSet* oop_maps,
430
int unpack_offset,
431
int unpack_with_exception_offset,
432
int unpack_with_reexecution_offset,
433
int frame_size)
434
{
435
DeoptimizationBlob* blob = NULL;
436
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
437
{
438
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
439
unsigned int size = allocation_size(cb, sizeof(DeoptimizationBlob));
440
blob = new (size) DeoptimizationBlob(cb,
441
size,
442
oop_maps,
443
unpack_offset,
444
unpack_with_exception_offset,
445
unpack_with_reexecution_offset,
446
frame_size);
447
}
448
449
trace_new_stub(blob, "DeoptimizationBlob");
450
451
return blob;
452
}
453
454
455
//----------------------------------------------------------------------------------------------------
456
// Implementation of UncommonTrapBlob
457
458
#ifdef COMPILER2
459
UncommonTrapBlob::UncommonTrapBlob(
460
CodeBuffer* cb,
461
int size,
462
OopMapSet* oop_maps,
463
int frame_size
464
)
465
: SingletonBlob("UncommonTrapBlob", cb, sizeof(UncommonTrapBlob), size, frame_size, oop_maps)
466
{}
467
468
469
UncommonTrapBlob* UncommonTrapBlob::create(
470
CodeBuffer* cb,
471
OopMapSet* oop_maps,
472
int frame_size)
473
{
474
UncommonTrapBlob* blob = NULL;
475
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
476
{
477
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
478
unsigned int size = allocation_size(cb, sizeof(UncommonTrapBlob));
479
blob = new (size) UncommonTrapBlob(cb, size, oop_maps, frame_size);
480
}
481
482
trace_new_stub(blob, "UncommonTrapBlob");
483
484
return blob;
485
}
486
487
488
#endif // COMPILER2
489
490
491
//----------------------------------------------------------------------------------------------------
492
// Implementation of ExceptionBlob
493
494
#ifdef COMPILER2
495
ExceptionBlob::ExceptionBlob(
496
CodeBuffer* cb,
497
int size,
498
OopMapSet* oop_maps,
499
int frame_size
500
)
501
: SingletonBlob("ExceptionBlob", cb, sizeof(ExceptionBlob), size, frame_size, oop_maps)
502
{}
503
504
505
ExceptionBlob* ExceptionBlob::create(
506
CodeBuffer* cb,
507
OopMapSet* oop_maps,
508
int frame_size)
509
{
510
ExceptionBlob* blob = NULL;
511
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
512
{
513
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
514
unsigned int size = allocation_size(cb, sizeof(ExceptionBlob));
515
blob = new (size) ExceptionBlob(cb, size, oop_maps, frame_size);
516
}
517
518
trace_new_stub(blob, "ExceptionBlob");
519
520
return blob;
521
}
522
523
524
#endif // COMPILER2
525
526
527
//----------------------------------------------------------------------------------------------------
528
// Implementation of SafepointBlob
529
530
SafepointBlob::SafepointBlob(
531
CodeBuffer* cb,
532
int size,
533
OopMapSet* oop_maps,
534
int frame_size
535
)
536
: SingletonBlob("SafepointBlob", cb, sizeof(SafepointBlob), size, frame_size, oop_maps)
537
{}
538
539
540
SafepointBlob* SafepointBlob::create(
541
CodeBuffer* cb,
542
OopMapSet* oop_maps,
543
int frame_size)
544
{
545
SafepointBlob* blob = NULL;
546
ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
547
{
548
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
549
unsigned int size = allocation_size(cb, sizeof(SafepointBlob));
550
blob = new (size) SafepointBlob(cb, size, oop_maps, frame_size);
551
}
552
553
trace_new_stub(blob, "SafepointBlob");
554
555
return blob;
556
}
557
558
559
//----------------------------------------------------------------------------------------------------
560
// Verification and printing
561
562
void CodeBlob::verify() {
563
ShouldNotReachHere();
564
}
565
566
void CodeBlob::print_on(outputStream* st) const {
567
st->print_cr("[CodeBlob (" INTPTR_FORMAT ")]", p2i(this));
568
st->print_cr("Framesize: %d", _frame_size);
569
}
570
571
void CodeBlob::print_value_on(outputStream* st) const {
572
st->print_cr("[CodeBlob]");
573
}
574
575
void BufferBlob::verify() {
576
// unimplemented
577
}
578
579
void BufferBlob::print_on(outputStream* st) const {
580
CodeBlob::print_on(st);
581
print_value_on(st);
582
}
583
584
void BufferBlob::print_value_on(outputStream* st) const {
585
st->print_cr("BufferBlob (" INTPTR_FORMAT ") used for %s", p2i(this), name());
586
}
587
588
void RuntimeStub::verify() {
589
// unimplemented
590
}
591
592
void RuntimeStub::print_on(outputStream* st) const {
593
ttyLocker ttyl;
594
CodeBlob::print_on(st);
595
st->print("Runtime Stub (" INTPTR_FORMAT "): ", p2i(this));
596
st->print_cr("%s", name());
597
Disassembler::decode((CodeBlob*)this, st);
598
}
599
600
void RuntimeStub::print_value_on(outputStream* st) const {
601
st->print("RuntimeStub (" INTPTR_FORMAT "): ", p2i(this)); st->print("%s", name());
602
}
603
604
void SingletonBlob::verify() {
605
// unimplemented
606
}
607
608
void SingletonBlob::print_on(outputStream* st) const {
609
ttyLocker ttyl;
610
CodeBlob::print_on(st);
611
st->print_cr("%s", name());
612
Disassembler::decode((CodeBlob*)this, st);
613
}
614
615
void SingletonBlob::print_value_on(outputStream* st) const {
616
st->print_cr("%s", name());
617
}
618
619
void DeoptimizationBlob::print_value_on(outputStream* st) const {
620
st->print_cr("Deoptimization (frame not available)");
621
}
622
623