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/interpreter/interpreterRuntime.cpp
32285 views
1
/*
2
* Copyright (c) 1997, 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 "classfile/systemDictionary.hpp"
27
#include "classfile/vmSymbols.hpp"
28
#include "compiler/compileBroker.hpp"
29
#include "compiler/disassembler.hpp"
30
#include "gc_interface/collectedHeap.hpp"
31
#include "interpreter/interpreter.hpp"
32
#include "interpreter/interpreterRuntime.hpp"
33
#include "interpreter/linkResolver.hpp"
34
#include "interpreter/templateTable.hpp"
35
#include "memory/oopFactory.hpp"
36
#include "memory/universe.inline.hpp"
37
#include "oops/constantPool.hpp"
38
#include "oops/instanceKlass.hpp"
39
#include "oops/methodData.hpp"
40
#include "oops/objArrayKlass.hpp"
41
#include "oops/oop.inline.hpp"
42
#include "oops/symbol.hpp"
43
#include "prims/jvmtiExport.hpp"
44
#include "prims/nativeLookup.hpp"
45
#include "runtime/biasedLocking.hpp"
46
#include "runtime/compilationPolicy.hpp"
47
#include "runtime/deoptimization.hpp"
48
#include "runtime/fieldDescriptor.hpp"
49
#include "runtime/handles.inline.hpp"
50
#include "runtime/interfaceSupport.hpp"
51
#include "runtime/java.hpp"
52
#include "runtime/jfieldIDWorkaround.hpp"
53
#include "runtime/osThread.hpp"
54
#include "runtime/sharedRuntime.hpp"
55
#include "runtime/stubRoutines.hpp"
56
#include "runtime/synchronizer.hpp"
57
#include "runtime/threadCritical.hpp"
58
#include "utilities/events.hpp"
59
#ifdef TARGET_ARCH_x86
60
# include "vm_version_x86.hpp"
61
#endif
62
#ifdef TARGET_ARCH_aarch32
63
# include "vm_version_aarch32.hpp"
64
#endif
65
#ifdef TARGET_ARCH_aarch64
66
# include "vm_version_aarch64.hpp"
67
#endif
68
#ifdef TARGET_ARCH_sparc
69
# include "vm_version_sparc.hpp"
70
#endif
71
#ifdef TARGET_ARCH_zero
72
# include "vm_version_zero.hpp"
73
#endif
74
#ifdef TARGET_ARCH_arm
75
# include "vm_version_arm.hpp"
76
#endif
77
#ifdef TARGET_ARCH_ppc
78
# include "vm_version_ppc.hpp"
79
#endif
80
#ifdef COMPILER2
81
#include "opto/runtime.hpp"
82
#endif
83
84
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
85
86
class UnlockFlagSaver {
87
private:
88
JavaThread* _thread;
89
bool _do_not_unlock;
90
public:
91
UnlockFlagSaver(JavaThread* t) {
92
_thread = t;
93
_do_not_unlock = t->do_not_unlock_if_synchronized();
94
t->set_do_not_unlock_if_synchronized(false);
95
}
96
~UnlockFlagSaver() {
97
_thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
98
}
99
};
100
101
//------------------------------------------------------------------------------------------------------------------------
102
// State accessors
103
104
void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread *thread) {
105
last_frame(thread).interpreter_frame_set_bcp(bcp);
106
if (ProfileInterpreter) {
107
// ProfileTraps uses MDOs independently of ProfileInterpreter.
108
// That is why we must check both ProfileInterpreter and mdo != NULL.
109
MethodData* mdo = last_frame(thread).interpreter_frame_method()->method_data();
110
if (mdo != NULL) {
111
NEEDS_CLEANUP;
112
last_frame(thread).interpreter_frame_set_mdp(mdo->bci_to_dp(last_frame(thread).interpreter_frame_bci()));
113
}
114
}
115
}
116
117
//------------------------------------------------------------------------------------------------------------------------
118
// Constants
119
120
121
IRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* thread, bool wide))
122
// access constant pool
123
ConstantPool* pool = method(thread)->constants();
124
int index = wide ? get_index_u2(thread, Bytecodes::_ldc_w) : get_index_u1(thread, Bytecodes::_ldc);
125
constantTag tag = pool->tag_at(index);
126
127
assert (tag.is_unresolved_klass() || tag.is_klass(), "wrong ldc call");
128
Klass* klass = pool->klass_at(index, CHECK);
129
oop java_class = klass->java_mirror();
130
thread->set_vm_result(java_class);
131
IRT_END
132
133
IRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* thread, Bytecodes::Code bytecode)) {
134
assert(bytecode == Bytecodes::_fast_aldc ||
135
bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
136
ResourceMark rm(thread);
137
methodHandle m (thread, method(thread));
138
Bytecode_loadconstant ldc(m, bci(thread));
139
oop result = ldc.resolve_constant(CHECK);
140
#ifdef ASSERT
141
{
142
// The bytecode wrappers aren't GC-safe so construct a new one
143
Bytecode_loadconstant ldc2(m, bci(thread));
144
oop coop = m->constants()->resolved_references()->obj_at(ldc2.cache_index());
145
assert(result == coop, "expected result for assembly code");
146
}
147
#endif
148
thread->set_vm_result(result);
149
}
150
IRT_END
151
152
153
//------------------------------------------------------------------------------------------------------------------------
154
// Allocation
155
156
IRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* thread, ConstantPool* pool, int index))
157
Klass* k_oop = pool->klass_at(index, CHECK);
158
instanceKlassHandle klass (THREAD, k_oop);
159
160
// Make sure we are not instantiating an abstract klass
161
klass->check_valid_for_instantiation(true, CHECK);
162
163
// Make sure klass is initialized
164
klass->initialize(CHECK);
165
166
// At this point the class may not be fully initialized
167
// because of recursive initialization. If it is fully
168
// initialized & has_finalized is not set, we rewrite
169
// it into its fast version (Note: no locking is needed
170
// here since this is an atomic byte write and can be
171
// done more than once).
172
//
173
// Note: In case of classes with has_finalized we don't
174
// rewrite since that saves us an extra check in
175
// the fast version which then would call the
176
// slow version anyway (and do a call back into
177
// Java).
178
// If we have a breakpoint, then we don't rewrite
179
// because the _breakpoint bytecode would be lost.
180
oop obj = klass->allocate_instance(CHECK);
181
thread->set_vm_result(obj);
182
IRT_END
183
184
185
IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size))
186
oop obj = oopFactory::new_typeArray(type, size, CHECK);
187
thread->set_vm_result(obj);
188
IRT_END
189
190
191
IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, ConstantPool* pool, int index, jint size))
192
// Note: no oopHandle for pool & klass needed since they are not used
193
// anymore after new_objArray() and no GC can happen before.
194
// (This may have to change if this code changes!)
195
Klass* klass = pool->klass_at(index, CHECK);
196
objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
197
thread->set_vm_result(obj);
198
IRT_END
199
200
201
IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address))
202
// We may want to pass in more arguments - could make this slightly faster
203
ConstantPool* constants = method(thread)->constants();
204
int i = get_index_u2(thread, Bytecodes::_multianewarray);
205
Klass* klass = constants->klass_at(i, CHECK);
206
int nof_dims = number_of_dimensions(thread);
207
assert(klass->is_klass(), "not a class");
208
assert(nof_dims >= 1, "multianewarray rank must be nonzero");
209
210
// We must create an array of jints to pass to multi_allocate.
211
ResourceMark rm(thread);
212
const int small_dims = 10;
213
jint dim_array[small_dims];
214
jint *dims = &dim_array[0];
215
if (nof_dims > small_dims) {
216
dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
217
}
218
for (int index = 0; index < nof_dims; index++) {
219
// offset from first_size_address is addressed as local[index]
220
int n = Interpreter::local_offset_in_bytes(index)/jintSize;
221
dims[index] = first_size_address[n];
222
}
223
oop obj = ArrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
224
thread->set_vm_result(obj);
225
IRT_END
226
227
228
IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
229
assert(obj->is_oop(), "must be a valid oop");
230
assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
231
InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
232
IRT_END
233
234
235
// Quicken instance-of and check-cast bytecodes
236
IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread))
237
// Force resolving; quicken the bytecode
238
int which = get_index_u2(thread, Bytecodes::_checkcast);
239
ConstantPool* cpool = method(thread)->constants();
240
// We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
241
// program we might have seen an unquick'd bytecode in the interpreter but have another
242
// thread quicken the bytecode before we get here.
243
// assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
244
Klass* klass = cpool->klass_at(which, CHECK);
245
thread->set_vm_result_2(klass);
246
IRT_END
247
248
249
//------------------------------------------------------------------------------------------------------------------------
250
// Exceptions
251
252
void InterpreterRuntime::note_trap_inner(JavaThread* thread, int reason,
253
methodHandle trap_method, int trap_bci, TRAPS) {
254
if (trap_method.not_null()) {
255
MethodData* trap_mdo = trap_method->method_data();
256
if (trap_mdo == NULL) {
257
Method::build_interpreter_method_data(trap_method, THREAD);
258
if (HAS_PENDING_EXCEPTION) {
259
assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())),
260
"we expect only an OOM error here");
261
CLEAR_PENDING_EXCEPTION;
262
}
263
trap_mdo = trap_method->method_data();
264
// and fall through...
265
}
266
if (trap_mdo != NULL) {
267
// Update per-method count of trap events. The interpreter
268
// is updating the MDO to simulate the effect of compiler traps.
269
Deoptimization::update_method_data_from_interpreter(trap_mdo, trap_bci, reason);
270
}
271
}
272
}
273
274
// Assume the compiler is (or will be) interested in this event.
275
// If necessary, create an MDO to hold the information, and record it.
276
void InterpreterRuntime::note_trap(JavaThread* thread, int reason, TRAPS) {
277
assert(ProfileTraps, "call me only if profiling");
278
methodHandle trap_method(thread, method(thread));
279
int trap_bci = trap_method->bci_from(bcp(thread));
280
note_trap_inner(thread, reason, trap_method, trap_bci, THREAD);
281
}
282
283
#ifdef CC_INTERP
284
// As legacy note_trap, but we have more arguments.
285
IRT_ENTRY(void, InterpreterRuntime::note_trap(JavaThread* thread, int reason, Method *method, int trap_bci))
286
methodHandle trap_method(method);
287
note_trap_inner(thread, reason, trap_method, trap_bci, THREAD);
288
IRT_END
289
290
// Class Deoptimization is not visible in BytecodeInterpreter, so we need a wrapper
291
// for each exception.
292
void InterpreterRuntime::note_nullCheck_trap(JavaThread* thread, Method *method, int trap_bci)
293
{ if (ProfileTraps) note_trap(thread, Deoptimization::Reason_null_check, method, trap_bci); }
294
void InterpreterRuntime::note_div0Check_trap(JavaThread* thread, Method *method, int trap_bci)
295
{ if (ProfileTraps) note_trap(thread, Deoptimization::Reason_div0_check, method, trap_bci); }
296
void InterpreterRuntime::note_rangeCheck_trap(JavaThread* thread, Method *method, int trap_bci)
297
{ if (ProfileTraps) note_trap(thread, Deoptimization::Reason_range_check, method, trap_bci); }
298
void InterpreterRuntime::note_classCheck_trap(JavaThread* thread, Method *method, int trap_bci)
299
{ if (ProfileTraps) note_trap(thread, Deoptimization::Reason_class_check, method, trap_bci); }
300
void InterpreterRuntime::note_arrayCheck_trap(JavaThread* thread, Method *method, int trap_bci)
301
{ if (ProfileTraps) note_trap(thread, Deoptimization::Reason_array_check, method, trap_bci); }
302
#endif // CC_INTERP
303
304
305
static Handle get_preinitialized_exception(Klass* k, TRAPS) {
306
// get klass
307
InstanceKlass* klass = InstanceKlass::cast(k);
308
assert(klass->is_initialized(),
309
"this klass should have been initialized during VM initialization");
310
// create instance - do not call constructor since we may have no
311
// (java) stack space left (should assert constructor is empty)
312
Handle exception;
313
oop exception_oop = klass->allocate_instance(CHECK_(exception));
314
exception = Handle(THREAD, exception_oop);
315
if (StackTraceInThrowable) {
316
java_lang_Throwable::fill_in_stack_trace(exception);
317
}
318
return exception;
319
}
320
321
// Special handling for stack overflow: since we don't have any (java) stack
322
// space left we use the pre-allocated & pre-initialized StackOverflowError
323
// klass to create an stack overflow error instance. We do not call its
324
// constructor for the same reason (it is empty, anyway).
325
IRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* thread))
326
Handle exception = get_preinitialized_exception(
327
SystemDictionary::StackOverflowError_klass(),
328
CHECK);
329
// Increment counter for hs_err file reporting
330
Atomic::inc(&Exceptions::_stack_overflow_errors);
331
THROW_HANDLE(exception);
332
IRT_END
333
334
335
IRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* thread, char* name, char* message))
336
// lookup exception klass
337
TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
338
if (ProfileTraps) {
339
if (s == vmSymbols::java_lang_ArithmeticException()) {
340
note_trap(thread, Deoptimization::Reason_div0_check, CHECK);
341
} else if (s == vmSymbols::java_lang_NullPointerException()) {
342
note_trap(thread, Deoptimization::Reason_null_check, CHECK);
343
}
344
}
345
// create exception
346
Handle exception = Exceptions::new_exception(thread, s, message);
347
thread->set_vm_result(exception());
348
IRT_END
349
350
351
IRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* thread, char* name, oopDesc* obj))
352
ResourceMark rm(thread);
353
const char* klass_name = obj->klass()->external_name();
354
// lookup exception klass
355
TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
356
if (ProfileTraps) {
357
note_trap(thread, Deoptimization::Reason_class_check, CHECK);
358
}
359
// create exception, with klass name as detail message
360
Handle exception = Exceptions::new_exception(thread, s, klass_name);
361
thread->set_vm_result(exception());
362
IRT_END
363
364
365
IRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index))
366
char message[jintAsStringSize];
367
// lookup exception klass
368
TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
369
if (ProfileTraps) {
370
note_trap(thread, Deoptimization::Reason_range_check, CHECK);
371
}
372
// create exception
373
sprintf(message, "%d", index);
374
THROW_MSG(s, message);
375
IRT_END
376
377
IRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException(
378
JavaThread* thread, oopDesc* obj))
379
380
ResourceMark rm(thread);
381
char* message = SharedRuntime::generate_class_cast_message(
382
thread, obj->klass()->external_name());
383
384
if (ProfileTraps) {
385
note_trap(thread, Deoptimization::Reason_class_check, CHECK);
386
}
387
388
// create exception
389
THROW_MSG(vmSymbols::java_lang_ClassCastException(), message);
390
IRT_END
391
392
// exception_handler_for_exception(...) returns the continuation address,
393
// the exception oop (via TLS) and sets the bci/bcp for the continuation.
394
// The exception oop is returned to make sure it is preserved over GC (it
395
// is only on the stack if the exception was thrown explicitly via athrow).
396
// During this operation, the expression stack contains the values for the
397
// bci where the exception happened. If the exception was propagated back
398
// from a call, the expression stack contains the values for the bci at the
399
// invoke w/o arguments (i.e., as if one were inside the call).
400
IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* thread, oopDesc* exception))
401
402
Handle h_exception(thread, exception);
403
methodHandle h_method (thread, method(thread));
404
constantPoolHandle h_constants(thread, h_method->constants());
405
bool should_repeat;
406
int handler_bci;
407
int current_bci = bci(thread);
408
409
if (thread->frames_to_pop_failed_realloc() > 0) {
410
// Allocation of scalar replaced object used in this frame
411
// failed. Unconditionally pop the frame.
412
thread->dec_frames_to_pop_failed_realloc();
413
thread->set_vm_result(h_exception());
414
// If the method is synchronized we already unlocked the monitor
415
// during deoptimization so the interpreter needs to skip it when
416
// the frame is popped.
417
thread->set_do_not_unlock_if_synchronized(true);
418
#ifdef CC_INTERP
419
return (address) -1;
420
#else
421
return Interpreter::remove_activation_entry();
422
#endif
423
}
424
425
// Need to do this check first since when _do_not_unlock_if_synchronized
426
// is set, we don't want to trigger any classloading which may make calls
427
// into java, or surprisingly find a matching exception handler for bci 0
428
// since at this moment the method hasn't been "officially" entered yet.
429
if (thread->do_not_unlock_if_synchronized()) {
430
ResourceMark rm;
431
assert(current_bci == 0, "bci isn't zero for do_not_unlock_if_synchronized");
432
thread->set_vm_result(exception);
433
#ifdef CC_INTERP
434
return (address) -1;
435
#else
436
return Interpreter::remove_activation_entry();
437
#endif
438
}
439
440
do {
441
should_repeat = false;
442
443
// assertions
444
#ifdef ASSERT
445
assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
446
assert(h_exception->is_oop(), "just checking");
447
// Check that exception is a subclass of Throwable, otherwise we have a VerifyError
448
if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
449
if (ExitVMOnVerifyError) vm_exit(-1);
450
ShouldNotReachHere();
451
}
452
#endif
453
454
// tracing
455
if (TraceExceptions) {
456
ResourceMark rm(thread);
457
Symbol* message = java_lang_Throwable::detail_message(h_exception());
458
ttyLocker ttyl; // Lock after getting the detail message
459
if (message != NULL) {
460
tty->print_cr("Exception <%s: %s> (" INTPTR_FORMAT ")",
461
h_exception->print_value_string(), message->as_C_string(),
462
(address)h_exception());
463
} else {
464
tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")",
465
h_exception->print_value_string(),
466
(address)h_exception());
467
}
468
tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string());
469
tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread);
470
}
471
// Don't go paging in something which won't be used.
472
// else if (extable->length() == 0) {
473
// // disabled for now - interpreter is not using shortcut yet
474
// // (shortcut is not to call runtime if we have no exception handlers)
475
// // warning("performance bug: should not call runtime if method has no exception handlers");
476
// }
477
// for AbortVMOnException flag
478
NOT_PRODUCT(Exceptions::debug_check_abort(h_exception));
479
480
// exception handler lookup
481
KlassHandle h_klass(THREAD, h_exception->klass());
482
handler_bci = Method::fast_exception_handler_bci_for(h_method, h_klass, current_bci, THREAD);
483
if (HAS_PENDING_EXCEPTION) {
484
// We threw an exception while trying to find the exception handler.
485
// Transfer the new exception to the exception handle which will
486
// be set into thread local storage, and do another lookup for an
487
// exception handler for this exception, this time starting at the
488
// BCI of the exception handler which caused the exception to be
489
// thrown (bug 4307310).
490
h_exception = Handle(THREAD, PENDING_EXCEPTION);
491
CLEAR_PENDING_EXCEPTION;
492
if (handler_bci >= 0) {
493
current_bci = handler_bci;
494
should_repeat = true;
495
}
496
}
497
} while (should_repeat == true);
498
499
// notify JVMTI of an exception throw; JVMTI will detect if this is a first
500
// time throw or a stack unwinding throw and accordingly notify the debugger
501
if (JvmtiExport::can_post_on_exceptions()) {
502
JvmtiExport::post_exception_throw(thread, h_method(), bcp(thread), h_exception());
503
}
504
505
#ifdef CC_INTERP
506
address continuation = (address)(intptr_t) handler_bci;
507
#else
508
address continuation = NULL;
509
#endif
510
address handler_pc = NULL;
511
if (handler_bci < 0 || !thread->reguard_stack((address) &continuation)) {
512
// Forward exception to callee (leaving bci/bcp untouched) because (a) no
513
// handler in this method, or (b) after a stack overflow there is not yet
514
// enough stack space available to reprotect the stack.
515
#ifndef CC_INTERP
516
continuation = Interpreter::remove_activation_entry();
517
#endif
518
// Count this for compilation purposes
519
h_method->interpreter_throwout_increment(THREAD);
520
} else {
521
// handler in this method => change bci/bcp to handler bci/bcp and continue there
522
handler_pc = h_method->code_base() + handler_bci;
523
#ifndef CC_INTERP
524
set_bcp_and_mdp(handler_pc, thread);
525
continuation = Interpreter::dispatch_table(vtos)[*handler_pc];
526
#endif
527
}
528
// notify debugger of an exception catch
529
// (this is good for exceptions caught in native methods as well)
530
if (JvmtiExport::can_post_on_exceptions()) {
531
JvmtiExport::notice_unwind_due_to_exception(thread, h_method(), handler_pc, h_exception(), (handler_pc != NULL));
532
}
533
534
thread->set_vm_result(h_exception());
535
return continuation;
536
IRT_END
537
538
539
IRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* thread))
540
assert(thread->has_pending_exception(), "must only ne called if there's an exception pending");
541
// nothing to do - eventually we should remove this code entirely (see comments @ call sites)
542
IRT_END
543
544
545
IRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* thread))
546
THROW(vmSymbols::java_lang_AbstractMethodError());
547
IRT_END
548
549
550
IRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* thread))
551
THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
552
IRT_END
553
554
555
//------------------------------------------------------------------------------------------------------------------------
556
// Fields
557
//
558
559
IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode))
560
// resolve field
561
fieldDescriptor info;
562
constantPoolHandle pool(thread, method(thread)->constants());
563
bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_putstatic);
564
bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
565
566
{
567
JvmtiHideSingleStepping jhss(thread);
568
LinkResolver::resolve_field_access(info, pool, get_index_u2_cpcache(thread, bytecode),
569
bytecode, CHECK);
570
} // end JvmtiHideSingleStepping
571
572
// check if link resolution caused cpCache to be updated
573
if (already_resolved(thread)) return;
574
575
// compute auxiliary field attributes
576
TosState state = as_TosState(info.field_type());
577
578
// We need to delay resolving put instructions on final fields
579
// until we actually invoke one. This is required so we throw
580
// exceptions at the correct place. If we do not resolve completely
581
// in the current pass, leaving the put_code set to zero will
582
// cause the next put instruction to reresolve.
583
Bytecodes::Code put_code = (Bytecodes::Code)0;
584
585
// We also need to delay resolving getstatic instructions until the
586
// class is intitialized. This is required so that access to the static
587
// field will call the initialization function every time until the class
588
// is completely initialized ala. in 2.17.5 in JVM Specification.
589
InstanceKlass* klass = InstanceKlass::cast(info.field_holder());
590
bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) &&
591
!klass->is_initialized());
592
Bytecodes::Code get_code = (Bytecodes::Code)0;
593
594
if (!uninitialized_static) {
595
get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
596
if (is_put || !info.access_flags().is_final()) {
597
put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
598
}
599
}
600
601
cache_entry(thread)->set_field(
602
get_code,
603
put_code,
604
info.field_holder(),
605
info.index(),
606
info.offset(),
607
state,
608
info.access_flags().is_final(),
609
info.access_flags().is_volatile(),
610
pool->pool_holder()
611
);
612
IRT_END
613
614
615
//------------------------------------------------------------------------------------------------------------------------
616
// Synchronization
617
//
618
// The interpreter's synchronization code is factored out so that it can
619
// be shared by method invocation and synchronized blocks.
620
//%note synchronization_3
621
622
//%note monitor_1
623
IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem))
624
#ifdef ASSERT
625
thread->last_frame().interpreter_frame_verify_monitor(elem);
626
#endif
627
if (PrintBiasedLockingStatistics) {
628
Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
629
}
630
Handle h_obj(thread, elem->obj());
631
assert(Universe::heap()->is_in_reserved_or_null(h_obj()),
632
"must be NULL or an object");
633
if (UseBiasedLocking) {
634
// Retry fast entry if bias is revoked to avoid unnecessary inflation
635
ObjectSynchronizer::fast_enter(h_obj, elem->lock(), true, CHECK);
636
} else {
637
ObjectSynchronizer::slow_enter(h_obj, elem->lock(), CHECK);
638
}
639
assert(Universe::heap()->is_in_reserved_or_null(elem->obj()),
640
"must be NULL or an object");
641
#ifdef ASSERT
642
thread->last_frame().interpreter_frame_verify_monitor(elem);
643
#endif
644
IRT_END
645
646
647
//%note monitor_1
648
IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem))
649
#ifdef ASSERT
650
thread->last_frame().interpreter_frame_verify_monitor(elem);
651
#endif
652
Handle h_obj(thread, elem->obj());
653
assert(Universe::heap()->is_in_reserved_or_null(h_obj()),
654
"must be NULL or an object");
655
if (elem == NULL || h_obj()->is_unlocked()) {
656
THROW(vmSymbols::java_lang_IllegalMonitorStateException());
657
}
658
ObjectSynchronizer::slow_exit(h_obj(), elem->lock(), thread);
659
// Free entry. This must be done here, since a pending exception might be installed on
660
// exit. If it is not cleared, the exception handling code will try to unlock the monitor again.
661
elem->set_obj(NULL);
662
#ifdef ASSERT
663
thread->last_frame().interpreter_frame_verify_monitor(elem);
664
#endif
665
IRT_END
666
667
668
IRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* thread))
669
THROW(vmSymbols::java_lang_IllegalMonitorStateException());
670
IRT_END
671
672
673
IRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* thread))
674
// Returns an illegal exception to install into the current thread. The
675
// pending_exception flag is cleared so normal exception handling does not
676
// trigger. Any current installed exception will be overwritten. This
677
// method will be called during an exception unwind.
678
679
assert(!HAS_PENDING_EXCEPTION, "no pending exception");
680
Handle exception(thread, thread->vm_result());
681
assert(exception() != NULL, "vm result should be set");
682
thread->set_vm_result(NULL); // clear vm result before continuing (may cause memory leaks and assert failures)
683
if (!exception->is_a(SystemDictionary::ThreadDeath_klass())) {
684
exception = get_preinitialized_exception(
685
SystemDictionary::IllegalMonitorStateException_klass(),
686
CATCH);
687
}
688
thread->set_vm_result(exception());
689
IRT_END
690
691
692
//------------------------------------------------------------------------------------------------------------------------
693
// Invokes
694
695
IRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* thread, Method* method, address bcp))
696
return method->orig_bytecode_at(method->bci_from(bcp));
697
IRT_END
698
699
IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, Method* method, address bcp, Bytecodes::Code new_code))
700
method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
701
IRT_END
702
703
IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, Method* method, address bcp))
704
JvmtiExport::post_raw_breakpoint(thread, method, bcp);
705
IRT_END
706
707
IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) {
708
// extract receiver from the outgoing argument list if necessary
709
Handle receiver(thread, NULL);
710
if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface ||
711
bytecode == Bytecodes::_invokespecial) {
712
ResourceMark rm(thread);
713
methodHandle m (thread, method(thread));
714
Bytecode_invoke call(m, bci(thread));
715
Symbol* signature = call.signature();
716
receiver = Handle(thread,
717
thread->last_frame().interpreter_callee_receiver(signature));
718
assert(Universe::heap()->is_in_reserved_or_null(receiver()),
719
"sanity check");
720
assert(receiver.is_null() ||
721
!Universe::heap()->is_in_reserved(receiver->klass()),
722
"sanity check");
723
}
724
725
// resolve method
726
CallInfo info;
727
constantPoolHandle pool(thread, method(thread)->constants());
728
729
{
730
JvmtiHideSingleStepping jhss(thread);
731
LinkResolver::resolve_invoke(info, receiver, pool,
732
get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
733
if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
734
int retry_count = 0;
735
while (info.resolved_method()->is_old()) {
736
// It is very unlikely that method is redefined more than 100 times
737
// in the middle of resolve. If it is looping here more than 100 times
738
// means then there could be a bug here.
739
guarantee((retry_count++ < 100),
740
"Could not resolve to latest version of redefined method");
741
// method is redefined in the middle of resolve so re-try.
742
LinkResolver::resolve_invoke(info, receiver, pool,
743
get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
744
}
745
}
746
} // end JvmtiHideSingleStepping
747
748
// check if link resolution caused cpCache to be updated
749
if (already_resolved(thread)) return;
750
751
if (bytecode == Bytecodes::_invokeinterface) {
752
if (TraceItables && Verbose) {
753
ResourceMark rm(thread);
754
tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string());
755
}
756
}
757
#ifdef ASSERT
758
if (bytecode == Bytecodes::_invokeinterface) {
759
if (info.resolved_method()->method_holder() ==
760
SystemDictionary::Object_klass()) {
761
// NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec
762
// (see also CallInfo::set_interface for details)
763
assert(info.call_kind() == CallInfo::vtable_call ||
764
info.call_kind() == CallInfo::direct_call, "");
765
methodHandle rm = info.resolved_method();
766
assert(rm->is_final() || info.has_vtable_index(),
767
"should have been set already");
768
} else if (!info.resolved_method()->has_itable_index()) {
769
// Resolved something like CharSequence.toString. Use vtable not itable.
770
assert(info.call_kind() != CallInfo::itable_call, "");
771
} else {
772
// Setup itable entry
773
assert(info.call_kind() == CallInfo::itable_call, "");
774
int index = info.resolved_method()->itable_index();
775
assert(info.itable_index() == index, "");
776
}
777
} else if (bytecode == Bytecodes::_invokespecial) {
778
assert(info.call_kind() == CallInfo::direct_call, "must be direct call");
779
} else {
780
assert(info.call_kind() == CallInfo::direct_call ||
781
info.call_kind() == CallInfo::vtable_call, "");
782
}
783
#endif
784
// Get sender or sender's host_klass, and only set cpCache entry to resolved if
785
// it is not an interface. The receiver for invokespecial calls within interface
786
// methods must be checked for every call.
787
InstanceKlass* sender = pool->pool_holder();
788
sender = sender->has_host_klass() ? InstanceKlass::cast(sender->host_klass()) : sender;
789
790
switch (info.call_kind()) {
791
case CallInfo::direct_call:
792
cache_entry(thread)->set_direct_call(
793
bytecode,
794
info.resolved_method(),
795
sender->is_interface());
796
break;
797
case CallInfo::vtable_call:
798
cache_entry(thread)->set_vtable_call(
799
bytecode,
800
info.resolved_method(),
801
info.vtable_index());
802
break;
803
case CallInfo::itable_call:
804
cache_entry(thread)->set_itable_call(
805
bytecode,
806
info.resolved_klass(),
807
info.resolved_method(),
808
info.itable_index());
809
break;
810
default: ShouldNotReachHere();
811
}
812
}
813
IRT_END
814
815
816
// First time execution: Resolve symbols, create a permanent MethodType object.
817
IRT_ENTRY(void, InterpreterRuntime::resolve_invokehandle(JavaThread* thread)) {
818
assert(EnableInvokeDynamic, "");
819
const Bytecodes::Code bytecode = Bytecodes::_invokehandle;
820
821
// resolve method
822
CallInfo info;
823
constantPoolHandle pool(thread, method(thread)->constants());
824
825
{
826
JvmtiHideSingleStepping jhss(thread);
827
LinkResolver::resolve_invoke(info, Handle(), pool,
828
get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
829
} // end JvmtiHideSingleStepping
830
831
cache_entry(thread)->set_method_handle(pool, info);
832
}
833
IRT_END
834
835
836
// First time execution: Resolve symbols, create a permanent CallSite object.
837
IRT_ENTRY(void, InterpreterRuntime::resolve_invokedynamic(JavaThread* thread)) {
838
assert(EnableInvokeDynamic, "");
839
const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
840
841
//TO DO: consider passing BCI to Java.
842
// int caller_bci = method(thread)->bci_from(bcp(thread));
843
844
// resolve method
845
CallInfo info;
846
constantPoolHandle pool(thread, method(thread)->constants());
847
int index = get_index_u4(thread, bytecode);
848
{
849
JvmtiHideSingleStepping jhss(thread);
850
LinkResolver::resolve_invoke(info, Handle(), pool,
851
index, bytecode, CHECK);
852
} // end JvmtiHideSingleStepping
853
854
ConstantPoolCacheEntry* cp_cache_entry = pool->invokedynamic_cp_cache_entry_at(index);
855
cp_cache_entry->set_dynamic_call(pool, info);
856
}
857
IRT_END
858
859
860
//------------------------------------------------------------------------------------------------------------------------
861
// Miscellaneous
862
863
864
nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) {
865
// Enable WXWrite: the function is called directly by interpreter.
866
MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, thread));
867
868
nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp);
869
assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests");
870
if (branch_bcp != NULL && nm != NULL) {
871
// This was a successful request for an OSR nmethod. Because
872
// frequency_counter_overflow_inner ends with a safepoint check,
873
// nm could have been unloaded so look it up again. It's unsafe
874
// to examine nm directly since it might have been freed and used
875
// for something else.
876
frame fr = thread->last_frame();
877
Method* method = fr.interpreter_frame_method();
878
int bci = method->bci_from(fr.interpreter_frame_bcp());
879
nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false);
880
}
881
#ifndef PRODUCT
882
if (TraceOnStackReplacement) {
883
if (nm != NULL) {
884
tty->print("OSR entry @ pc: " INTPTR_FORMAT ": ", nm->osr_entry());
885
nm->print();
886
}
887
}
888
#endif
889
return nm;
890
}
891
892
IRT_ENTRY(nmethod*,
893
InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp))
894
// use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
895
// flag, in case this method triggers classloading which will call into Java.
896
UnlockFlagSaver fs(thread);
897
898
frame fr = thread->last_frame();
899
assert(fr.is_interpreted_frame(), "must come from interpreter");
900
methodHandle method(thread, fr.interpreter_frame_method());
901
const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci;
902
const int bci = branch_bcp != NULL ? method->bci_from(fr.interpreter_frame_bcp()) : InvocationEntryBci;
903
904
assert(!HAS_PENDING_EXCEPTION, "Should not have any exceptions pending");
905
nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, NULL, thread);
906
assert(!HAS_PENDING_EXCEPTION, "Event handler should not throw any exceptions");
907
908
if (osr_nm != NULL) {
909
// We may need to do on-stack replacement which requires that no
910
// monitors in the activation are biased because their
911
// BasicObjectLocks will need to migrate during OSR. Force
912
// unbiasing of all monitors in the activation now (even though
913
// the OSR nmethod might be invalidated) because we don't have a
914
// safepoint opportunity later once the migration begins.
915
if (UseBiasedLocking) {
916
ResourceMark rm;
917
GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
918
for( BasicObjectLock *kptr = fr.interpreter_frame_monitor_end();
919
kptr < fr.interpreter_frame_monitor_begin();
920
kptr = fr.next_monitor_in_interpreter_frame(kptr) ) {
921
if( kptr->obj() != NULL ) {
922
objects_to_revoke->append(Handle(THREAD, kptr->obj()));
923
}
924
}
925
BiasedLocking::revoke(objects_to_revoke);
926
}
927
}
928
return osr_nm;
929
IRT_END
930
931
IRT_LEAF(jint, InterpreterRuntime::bcp_to_di(Method* method, address cur_bcp))
932
assert(ProfileInterpreter, "must be profiling interpreter");
933
int bci = method->bci_from(cur_bcp);
934
MethodData* mdo = method->method_data();
935
if (mdo == NULL) return 0;
936
return mdo->bci_to_di(bci);
937
IRT_END
938
939
IRT_ENTRY(void, InterpreterRuntime::profile_method(JavaThread* thread))
940
// use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
941
// flag, in case this method triggers classloading which will call into Java.
942
UnlockFlagSaver fs(thread);
943
944
assert(ProfileInterpreter, "must be profiling interpreter");
945
frame fr = thread->last_frame();
946
assert(fr.is_interpreted_frame(), "must come from interpreter");
947
methodHandle method(thread, fr.interpreter_frame_method());
948
Method::build_interpreter_method_data(method, THREAD);
949
if (HAS_PENDING_EXCEPTION) {
950
assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
951
CLEAR_PENDING_EXCEPTION;
952
// and fall through...
953
}
954
IRT_END
955
956
957
#ifdef ASSERT
958
IRT_LEAF(void, InterpreterRuntime::verify_mdp(Method* method, address bcp, address mdp))
959
assert(ProfileInterpreter, "must be profiling interpreter");
960
961
MethodData* mdo = method->method_data();
962
assert(mdo != NULL, "must not be null");
963
964
int bci = method->bci_from(bcp);
965
966
address mdp2 = mdo->bci_to_dp(bci);
967
if (mdp != mdp2) {
968
ResourceMark rm;
969
ResetNoHandleMark rnm; // In a LEAF entry.
970
HandleMark hm;
971
tty->print_cr("FAILED verify : actual mdp %p expected mdp %p @ bci %d", mdp, mdp2, bci);
972
int current_di = mdo->dp_to_di(mdp);
973
int expected_di = mdo->dp_to_di(mdp2);
974
tty->print_cr(" actual di %d expected di %d", current_di, expected_di);
975
int expected_approx_bci = mdo->data_at(expected_di)->bci();
976
int approx_bci = -1;
977
if (current_di >= 0) {
978
approx_bci = mdo->data_at(current_di)->bci();
979
}
980
tty->print_cr(" actual bci is %d expected bci %d", approx_bci, expected_approx_bci);
981
mdo->print_on(tty);
982
method->print_codes();
983
}
984
assert(mdp == mdp2, "wrong mdp");
985
IRT_END
986
#endif // ASSERT
987
988
IRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* thread, int return_bci))
989
assert(ProfileInterpreter, "must be profiling interpreter");
990
ResourceMark rm(thread);
991
HandleMark hm(thread);
992
frame fr = thread->last_frame();
993
assert(fr.is_interpreted_frame(), "must come from interpreter");
994
MethodData* h_mdo = fr.interpreter_frame_method()->method_data();
995
996
// Grab a lock to ensure atomic access to setting the return bci and
997
// the displacement. This can block and GC, invalidating all naked oops.
998
MutexLocker ml(RetData_lock);
999
1000
// ProfileData is essentially a wrapper around a derived oop, so we
1001
// need to take the lock before making any ProfileData structures.
1002
ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(fr.interpreter_frame_mdp()));
1003
guarantee(data != NULL, "profile data must be valid");
1004
RetData* rdata = data->as_RetData();
1005
address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
1006
fr.interpreter_frame_set_mdp(new_mdp);
1007
IRT_END
1008
1009
IRT_ENTRY(MethodCounters*, InterpreterRuntime::build_method_counters(JavaThread* thread, Method* m))
1010
MethodCounters* mcs = Method::build_method_counters(m, thread);
1011
if (HAS_PENDING_EXCEPTION) {
1012
assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
1013
CLEAR_PENDING_EXCEPTION;
1014
}
1015
return mcs;
1016
IRT_END
1017
1018
1019
IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread))
1020
// We used to need an explict preserve_arguments here for invoke bytecodes. However,
1021
// stack traversal automatically takes care of preserving arguments for invoke, so
1022
// this is no longer needed.
1023
1024
// IRT_END does an implicit safepoint check, hence we are guaranteed to block
1025
// if this is called during a safepoint
1026
1027
if (JvmtiExport::should_post_single_step()) {
1028
// We are called during regular safepoints and when the VM is
1029
// single stepping. If any thread is marked for single stepping,
1030
// then we may have JVMTI work to do.
1031
JvmtiExport::at_single_stepping_point(thread, method(thread), bcp(thread));
1032
}
1033
IRT_END
1034
1035
IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj,
1036
ConstantPoolCacheEntry *cp_entry))
1037
1038
// check the access_flags for the field in the klass
1039
1040
InstanceKlass* ik = InstanceKlass::cast(cp_entry->f1_as_klass());
1041
int index = cp_entry->field_index();
1042
if ((ik->field_access_flags(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
1043
1044
switch(cp_entry->flag_state()) {
1045
case btos: // fall through
1046
case ztos: // fall through
1047
case ctos: // fall through
1048
case stos: // fall through
1049
case itos: // fall through
1050
case ftos: // fall through
1051
case ltos: // fall through
1052
case dtos: // fall through
1053
case atos: break;
1054
default: ShouldNotReachHere(); return;
1055
}
1056
bool is_static = (obj == NULL);
1057
HandleMark hm(thread);
1058
1059
Handle h_obj;
1060
if (!is_static) {
1061
// non-static field accessors have an object, but we need a handle
1062
h_obj = Handle(thread, obj);
1063
}
1064
instanceKlassHandle h_cp_entry_f1(thread, (Klass*)cp_entry->f1_as_klass());
1065
jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_cp_entry_f1, cp_entry->f2_as_index(), is_static);
1066
JvmtiExport::post_field_access(thread, method(thread), bcp(thread), h_cp_entry_f1, h_obj, fid);
1067
IRT_END
1068
1069
IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread,
1070
oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value))
1071
1072
Klass* k = (Klass*)cp_entry->f1_as_klass();
1073
1074
// check the access_flags for the field in the klass
1075
InstanceKlass* ik = InstanceKlass::cast(k);
1076
int index = cp_entry->field_index();
1077
// bail out if field modifications are not watched
1078
if ((ik->field_access_flags(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
1079
1080
char sig_type = '\0';
1081
1082
switch(cp_entry->flag_state()) {
1083
case btos: sig_type = 'B'; break;
1084
case ztos: sig_type = 'Z'; break;
1085
case ctos: sig_type = 'C'; break;
1086
case stos: sig_type = 'S'; break;
1087
case itos: sig_type = 'I'; break;
1088
case ftos: sig_type = 'F'; break;
1089
case atos: sig_type = 'L'; break;
1090
case ltos: sig_type = 'J'; break;
1091
case dtos: sig_type = 'D'; break;
1092
default: ShouldNotReachHere(); return;
1093
}
1094
bool is_static = (obj == NULL);
1095
1096
HandleMark hm(thread);
1097
instanceKlassHandle h_klass(thread, k);
1098
jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_klass, cp_entry->f2_as_index(), is_static);
1099
jvalue fvalue;
1100
#ifdef _LP64
1101
fvalue = *value;
1102
#else
1103
// Long/double values are stored unaligned and also noncontiguously with
1104
// tagged stacks. We can't just do a simple assignment even in the non-
1105
// J/D cases because a C++ compiler is allowed to assume that a jvalue is
1106
// 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1107
// We assume that the two halves of longs/doubles are stored in interpreter
1108
// stack slots in platform-endian order.
1109
jlong_accessor u;
1110
jint* newval = (jint*)value;
1111
u.words[0] = newval[0];
1112
u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1113
fvalue.j = u.long_value;
1114
#endif // _LP64
1115
1116
Handle h_obj;
1117
if (!is_static) {
1118
// non-static field accessors have an object, but we need a handle
1119
h_obj = Handle(thread, obj);
1120
}
1121
1122
JvmtiExport::post_raw_field_modification(thread, method(thread), bcp(thread), h_klass, h_obj,
1123
fid, sig_type, &fvalue);
1124
IRT_END
1125
1126
IRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *thread))
1127
JvmtiExport::post_method_entry(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
1128
IRT_END
1129
1130
1131
IRT_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *thread))
1132
JvmtiExport::post_method_exit(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
1133
IRT_END
1134
1135
IRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc))
1136
{
1137
return (Interpreter::contains(pc) ? 1 : 0);
1138
}
1139
IRT_END
1140
1141
1142
// Implementation of SignatureHandlerLibrary
1143
1144
address SignatureHandlerLibrary::set_handler_blob() {
1145
BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);
1146
if (handler_blob == NULL) {
1147
return NULL;
1148
}
1149
address handler = handler_blob->code_begin();
1150
_handler_blob = handler_blob;
1151
_handler = handler;
1152
return handler;
1153
}
1154
1155
void SignatureHandlerLibrary::initialize() {
1156
if (_fingerprints != NULL) {
1157
return;
1158
}
1159
if (set_handler_blob() == NULL) {
1160
vm_exit_out_of_memory(blob_size, OOM_MALLOC_ERROR, "native signature handlers");
1161
}
1162
1163
BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer",
1164
SignatureHandlerLibrary::buffer_size);
1165
_buffer = bb->code_begin();
1166
1167
_fingerprints = new(ResourceObj::C_HEAP, mtCode)GrowableArray<uint64_t>(32, true);
1168
_handlers = new(ResourceObj::C_HEAP, mtCode)GrowableArray<address>(32, true);
1169
}
1170
1171
address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) {
1172
address handler = _handler;
1173
int insts_size = buffer->pure_insts_size();
1174
if (handler + insts_size > _handler_blob->code_end()) {
1175
// get a new handler blob
1176
handler = set_handler_blob();
1177
}
1178
if (handler != NULL) {
1179
memcpy(handler, buffer->insts_begin(), insts_size);
1180
pd_set_handler(handler);
1181
ICache::invalidate_range(handler, insts_size);
1182
_handler = handler + insts_size;
1183
}
1184
return handler;
1185
}
1186
1187
void SignatureHandlerLibrary::add(methodHandle method) {
1188
if (method->signature_handler() == NULL) {
1189
// use slow signature handler if we can't do better
1190
int handler_index = -1;
1191
// check if we can use customized (fast) signature handler
1192
if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) {
1193
// use customized signature handler
1194
MutexLocker mu(SignatureHandlerLibrary_lock);
1195
// make sure data structure is initialized
1196
initialize();
1197
// lookup method signature's fingerprint
1198
uint64_t fingerprint = Fingerprinter(method).fingerprint();
1199
handler_index = _fingerprints->find(fingerprint);
1200
// create handler if necessary
1201
if (handler_index < 0) {
1202
ResourceMark rm;
1203
ptrdiff_t align_offset = (address)
1204
round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer;
1205
CodeBuffer buffer((address)(_buffer + align_offset),
1206
SignatureHandlerLibrary::buffer_size - align_offset);
1207
InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint);
1208
// copy into code heap
1209
address handler = set_handler(&buffer);
1210
if (handler == NULL) {
1211
// use slow signature handler
1212
} else {
1213
// debugging suppport
1214
if (PrintSignatureHandlers) {
1215
ttyLocker ttyl;
1216
tty->cr();
1217
tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",
1218
_handlers->length(),
1219
(method->is_static() ? "static" : "receiver"),
1220
method->name_and_sig_as_C_string(),
1221
fingerprint,
1222
buffer.insts_size());
1223
Disassembler::decode(handler, handler + buffer.insts_size());
1224
#ifndef PRODUCT
1225
tty->print_cr(" --- associated result handler ---");
1226
address rh_begin = Interpreter::result_handler(method()->result_type());
1227
address rh_end = rh_begin;
1228
while (*(int*)rh_end != 0) {
1229
rh_end += sizeof(int);
1230
}
1231
Disassembler::decode(rh_begin, rh_end);
1232
#endif
1233
}
1234
// add handler to library
1235
_fingerprints->append(fingerprint);
1236
_handlers->append(handler);
1237
// set handler index
1238
assert(_fingerprints->length() == _handlers->length(), "sanity check");
1239
handler_index = _fingerprints->length() - 1;
1240
}
1241
}
1242
// Set handler under SignatureHandlerLibrary_lock
1243
if (handler_index < 0) {
1244
// use generic signature handler
1245
method->set_signature_handler(Interpreter::slow_signature_handler());
1246
} else {
1247
// set handler
1248
method->set_signature_handler(_handlers->at(handler_index));
1249
}
1250
} else {
1251
CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
1252
// use generic signature handler
1253
method->set_signature_handler(Interpreter::slow_signature_handler());
1254
}
1255
}
1256
#ifdef ASSERT
1257
int handler_index = -1;
1258
int fingerprint_index = -2;
1259
{
1260
// '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized
1261
// in any way if accessed from multiple threads. To avoid races with another
1262
// thread which may change the arrays in the above, mutex protected block, we
1263
// have to protect this read access here with the same mutex as well!
1264
MutexLocker mu(SignatureHandlerLibrary_lock);
1265
if (_handlers != NULL) {
1266
handler_index = _handlers->find(method->signature_handler());
1267
fingerprint_index = _fingerprints->find(Fingerprinter(method).fingerprint());
1268
}
1269
}
1270
assert(method->signature_handler() == Interpreter::slow_signature_handler() ||
1271
handler_index == fingerprint_index, "sanity check");
1272
#endif // ASSERT
1273
}
1274
1275
1276
BufferBlob* SignatureHandlerLibrary::_handler_blob = NULL;
1277
address SignatureHandlerLibrary::_handler = NULL;
1278
GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL;
1279
GrowableArray<address>* SignatureHandlerLibrary::_handlers = NULL;
1280
address SignatureHandlerLibrary::_buffer = NULL;
1281
1282
1283
IRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* thread, Method* method))
1284
methodHandle m(thread, method);
1285
assert(m->is_native(), "sanity check");
1286
// lookup native function entry point if it doesn't exist
1287
bool in_base_library;
1288
if (!m->has_native_function()) {
1289
NativeLookup::lookup(m, in_base_library, CHECK);
1290
}
1291
// make sure signature handler is installed
1292
SignatureHandlerLibrary::add(m);
1293
// The interpreter entry point checks the signature handler first,
1294
// before trying to fetch the native entry point and klass mirror.
1295
// We must set the signature handler last, so that multiple processors
1296
// preparing the same method will be sure to see non-null entry & mirror.
1297
IRT_END
1298
1299
#if defined(IA32) || defined(AMD64) || defined(ARM) || defined(AARCH64)
1300
IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address))
1301
if (src_address == dest_address) {
1302
return;
1303
}
1304
ResetNoHandleMark rnm; // In a LEAF entry.
1305
HandleMark hm;
1306
ResourceMark rm;
1307
frame fr = thread->last_frame();
1308
assert(fr.is_interpreted_frame(), "");
1309
jint bci = fr.interpreter_frame_bci();
1310
methodHandle mh(thread, fr.interpreter_frame_method());
1311
Bytecode_invoke invoke(mh, bci);
1312
ArgumentSizeComputer asc(invoke.signature());
1313
int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
1314
Copy::conjoint_jbytes(src_address, dest_address,
1315
size_of_arguments * Interpreter::stackElementSize);
1316
IRT_END
1317
#endif
1318
1319
#if INCLUDE_JVMTI
1320
// This is a support of the JVMTI PopFrame interface.
1321
// Make sure it is an invokestatic of a polymorphic intrinsic that has a member_name argument
1322
// and return it as a vm_result so that it can be reloaded in the list of invokestatic parameters.
1323
// The member_name argument is a saved reference (in local#0) to the member_name.
1324
// For backward compatibility with some JDK versions (7, 8) it can also be a direct method handle.
1325
// FIXME: remove DMH case after j.l.i.InvokerBytecodeGenerator code shape is updated.
1326
IRT_ENTRY(void, InterpreterRuntime::member_name_arg_or_null(JavaThread* thread, address member_name,
1327
Method* method, address bcp))
1328
Bytecodes::Code code = Bytecodes::code_at(method, bcp);
1329
if (code != Bytecodes::_invokestatic) {
1330
return;
1331
}
1332
ConstantPool* cpool = method->constants();
1333
int cp_index = Bytes::get_native_u2(bcp + 1) + ConstantPool::CPCACHE_INDEX_TAG;
1334
Symbol* cname = cpool->klass_name_at(cpool->klass_ref_index_at(cp_index));
1335
Symbol* mname = cpool->name_ref_at(cp_index);
1336
1337
if (MethodHandles::has_member_arg(cname, mname)) {
1338
oop member_name_oop = (oop) member_name;
1339
if (java_lang_invoke_DirectMethodHandle::is_instance(member_name_oop)) {
1340
// FIXME: remove after j.l.i.InvokerBytecodeGenerator code shape is updated.
1341
member_name_oop = java_lang_invoke_DirectMethodHandle::member(member_name_oop);
1342
}
1343
thread->set_vm_result(member_name_oop);
1344
} else {
1345
thread->set_vm_result(NULL);
1346
}
1347
IRT_END
1348
#endif // INCLUDE_JVMTI
1349
1350