Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/zero/vm/cppInterpreter_zero.cpp
32285 views
1
/*
2
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
3
* Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*
24
*/
25
26
#include "precompiled.hpp"
27
#include "asm/assembler.hpp"
28
#include "interpreter/bytecodeHistogram.hpp"
29
#include "interpreter/cppInterpreter.hpp"
30
#include "interpreter/interpreter.hpp"
31
#include "interpreter/interpreterGenerator.hpp"
32
#include "interpreter/interpreterRuntime.hpp"
33
#include "oops/arrayOop.hpp"
34
#include "oops/methodData.hpp"
35
#include "oops/method.hpp"
36
#include "oops/oop.inline.hpp"
37
#include "prims/jvmtiExport.hpp"
38
#include "prims/jvmtiThreadState.hpp"
39
#include "runtime/arguments.hpp"
40
#include "runtime/deoptimization.hpp"
41
#include "runtime/frame.inline.hpp"
42
#include "runtime/interfaceSupport.hpp"
43
#include "runtime/orderAccess.inline.hpp"
44
#include "runtime/sharedRuntime.hpp"
45
#include "runtime/stubRoutines.hpp"
46
#include "runtime/synchronizer.hpp"
47
#include "runtime/timer.hpp"
48
#include "runtime/vframeArray.hpp"
49
#include "stack_zero.inline.hpp"
50
#include "utilities/debug.hpp"
51
#include "utilities/macros.hpp"
52
#ifdef SHARK
53
#include "shark/shark_globals.hpp"
54
#endif
55
56
#ifdef CC_INTERP
57
58
#define fixup_after_potential_safepoint() \
59
method = istate->method()
60
61
#define CALL_VM_NOCHECK_NOFIX(func) \
62
thread->set_last_Java_frame(); \
63
func; \
64
thread->reset_last_Java_frame();
65
66
#define CALL_VM_NOCHECK(func) \
67
CALL_VM_NOCHECK_NOFIX(func) \
68
fixup_after_potential_safepoint()
69
70
int CppInterpreter::normal_entry(Method* method, intptr_t UNUSED, TRAPS) {
71
JavaThread *thread = (JavaThread *) THREAD;
72
73
// Allocate and initialize our frame.
74
InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0);
75
thread->push_zero_frame(frame);
76
77
// Execute those bytecodes!
78
main_loop(0, THREAD);
79
80
// No deoptimized frames on the stack
81
return 0;
82
}
83
84
intptr_t narrow(BasicType type, intptr_t result) {
85
// mask integer result to narrower return type.
86
switch (type) {
87
case T_BOOLEAN:
88
return result&1;
89
case T_BYTE:
90
return (intptr_t)(jbyte)result;
91
case T_CHAR:
92
return (intptr_t)(uintptr_t)(jchar)result;
93
case T_SHORT:
94
return (intptr_t)(jshort)result;
95
case T_OBJECT: // nothing to do fall through
96
case T_ARRAY:
97
case T_LONG:
98
case T_INT:
99
case T_FLOAT:
100
case T_DOUBLE:
101
case T_VOID:
102
return result;
103
default:
104
ShouldNotReachHere();
105
return result; // silence compiler warnings
106
}
107
}
108
109
110
void CppInterpreter::main_loop(int recurse, TRAPS) {
111
JavaThread *thread = (JavaThread *) THREAD;
112
ZeroStack *stack = thread->zero_stack();
113
114
// If we are entering from a deopt we may need to call
115
// ourself a few times in order to get to our frame.
116
if (recurse)
117
main_loop(recurse - 1, THREAD);
118
119
InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame();
120
interpreterState istate = frame->interpreter_state();
121
Method* method = istate->method();
122
123
intptr_t *result = NULL;
124
int result_slots = 0;
125
126
while (true) {
127
// We can set up the frame anchor with everything we want at
128
// this point as we are thread_in_Java and no safepoints can
129
// occur until we go to vm mode. We do have to clear flags
130
// on return from vm but that is it.
131
thread->set_last_Java_frame();
132
133
// Call the interpreter
134
if (JvmtiExport::can_post_interpreter_events())
135
BytecodeInterpreter::runWithChecks(istate);
136
else
137
BytecodeInterpreter::run(istate);
138
fixup_after_potential_safepoint();
139
140
// Clear the frame anchor
141
thread->reset_last_Java_frame();
142
143
// Examine the message from the interpreter to decide what to do
144
if (istate->msg() == BytecodeInterpreter::call_method) {
145
Method* callee = istate->callee();
146
147
// Trim back the stack to put the parameters at the top
148
stack->set_sp(istate->stack() + 1);
149
150
// Make the call
151
Interpreter::invoke_method(callee, istate->callee_entry_point(), THREAD);
152
fixup_after_potential_safepoint();
153
154
// Convert the result
155
istate->set_stack(stack->sp() - 1);
156
157
// Restore the stack
158
stack->set_sp(istate->stack_limit() + 1);
159
160
// Resume the interpreter
161
istate->set_msg(BytecodeInterpreter::method_resume);
162
}
163
else if (istate->msg() == BytecodeInterpreter::more_monitors) {
164
int monitor_words = frame::interpreter_frame_monitor_size();
165
166
// Allocate the space
167
stack->overflow_check(monitor_words, THREAD);
168
if (HAS_PENDING_EXCEPTION)
169
break;
170
stack->alloc(monitor_words * wordSize);
171
172
// Move the expression stack contents
173
for (intptr_t *p = istate->stack() + 1; p < istate->stack_base(); p++)
174
*(p - monitor_words) = *p;
175
176
// Move the expression stack pointers
177
istate->set_stack_limit(istate->stack_limit() - monitor_words);
178
istate->set_stack(istate->stack() - monitor_words);
179
istate->set_stack_base(istate->stack_base() - monitor_words);
180
181
// Zero the new monitor so the interpreter can find it.
182
((BasicObjectLock *) istate->stack_base())->set_obj(NULL);
183
184
// Resume the interpreter
185
istate->set_msg(BytecodeInterpreter::got_monitors);
186
}
187
else if (istate->msg() == BytecodeInterpreter::return_from_method) {
188
// Copy the result into the caller's frame
189
result_slots = type2size[method->result_type()];
190
assert(result_slots >= 0 && result_slots <= 2, "what?");
191
result = istate->stack() + result_slots;
192
break;
193
}
194
else if (istate->msg() == BytecodeInterpreter::throwing_exception) {
195
assert(HAS_PENDING_EXCEPTION, "should do");
196
break;
197
}
198
else if (istate->msg() == BytecodeInterpreter::do_osr) {
199
// Unwind the current frame
200
thread->pop_zero_frame();
201
202
// Remove any extension of the previous frame
203
int extra_locals = method->max_locals() - method->size_of_parameters();
204
stack->set_sp(stack->sp() + extra_locals);
205
206
// Jump into the OSR method
207
Interpreter::invoke_osr(
208
method, istate->osr_entry(), istate->osr_buf(), THREAD);
209
return;
210
}
211
else {
212
ShouldNotReachHere();
213
}
214
}
215
216
// Unwind the current frame
217
thread->pop_zero_frame();
218
219
// Pop our local variables
220
stack->set_sp(stack->sp() + method->max_locals());
221
222
// Push our result
223
for (int i = 0; i < result_slots; i++) {
224
// Adjust result to smaller
225
union {
226
intptr_t res;
227
jint res_jint;
228
};
229
res = result[-i];
230
if (result_slots == 1) {
231
BasicType t = method->result_type();
232
if (is_subword_type(t)) {
233
res_jint = (jint)narrow(t, res_jint);
234
}
235
}
236
stack->push(res);
237
}
238
}
239
240
int CppInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) {
241
// Make sure method is native and not abstract
242
assert(method->is_native() && !method->is_abstract(), "should be");
243
244
JavaThread *thread = (JavaThread *) THREAD;
245
ZeroStack *stack = thread->zero_stack();
246
247
// Allocate and initialize our frame
248
InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0);
249
thread->push_zero_frame(frame);
250
interpreterState istate = frame->interpreter_state();
251
intptr_t *locals = istate->locals();
252
253
// Update the invocation counter
254
if ((UseCompiler || CountCompiledCalls) && !method->is_synchronized()) {
255
MethodCounters* mcs = method->method_counters();
256
if (mcs == NULL) {
257
CALL_VM_NOCHECK(mcs = InterpreterRuntime::build_method_counters(thread, method));
258
if (HAS_PENDING_EXCEPTION)
259
goto unwind_and_return;
260
}
261
InvocationCounter *counter = mcs->invocation_counter();
262
counter->increment();
263
if (counter->reached_InvocationLimit(mcs->backedge_counter())) {
264
CALL_VM_NOCHECK(
265
InterpreterRuntime::frequency_counter_overflow(thread, NULL));
266
if (HAS_PENDING_EXCEPTION)
267
goto unwind_and_return;
268
}
269
}
270
271
// Lock if necessary
272
BasicObjectLock *monitor;
273
monitor = NULL;
274
if (method->is_synchronized()) {
275
monitor = (BasicObjectLock*) istate->stack_base();
276
oop lockee = monitor->obj();
277
markOop disp = lockee->mark()->set_unlocked();
278
279
monitor->lock()->set_displaced_header(disp);
280
if (Atomic::cmpxchg_ptr(monitor, lockee->mark_addr(), disp) != disp) {
281
if (thread->is_lock_owned((address) disp->clear_lock_bits())) {
282
monitor->lock()->set_displaced_header(NULL);
283
}
284
else {
285
CALL_VM_NOCHECK(InterpreterRuntime::monitorenter(thread, monitor));
286
if (HAS_PENDING_EXCEPTION)
287
goto unwind_and_return;
288
}
289
}
290
}
291
292
// Get the signature handler
293
InterpreterRuntime::SignatureHandler *handler; {
294
address handlerAddr = method->signature_handler();
295
if (handlerAddr == NULL) {
296
CALL_VM_NOCHECK(InterpreterRuntime::prepare_native_call(thread, method));
297
if (HAS_PENDING_EXCEPTION)
298
goto unlock_unwind_and_return;
299
300
handlerAddr = method->signature_handler();
301
assert(handlerAddr != NULL, "eh?");
302
}
303
if (handlerAddr == (address) InterpreterRuntime::slow_signature_handler) {
304
CALL_VM_NOCHECK(handlerAddr =
305
InterpreterRuntime::slow_signature_handler(thread, method, NULL,NULL));
306
if (HAS_PENDING_EXCEPTION)
307
goto unlock_unwind_and_return;
308
}
309
handler = \
310
InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr);
311
}
312
313
// Get the native function entry point
314
address function;
315
function = method->native_function();
316
assert(function != NULL, "should be set if signature handler is");
317
318
// Build the argument list
319
stack->overflow_check(handler->argument_count() * 2, THREAD);
320
if (HAS_PENDING_EXCEPTION)
321
goto unlock_unwind_and_return;
322
323
void **arguments;
324
void *mirror; {
325
arguments =
326
(void **) stack->alloc(handler->argument_count() * sizeof(void **));
327
void **dst = arguments;
328
329
void *env = thread->jni_environment();
330
*(dst++) = &env;
331
332
if (method->is_static()) {
333
istate->set_oop_temp(
334
method->constants()->pool_holder()->java_mirror());
335
mirror = istate->oop_temp_addr();
336
*(dst++) = &mirror;
337
}
338
339
intptr_t *src = locals;
340
for (int i = dst - arguments; i < handler->argument_count(); i++) {
341
ffi_type *type = handler->argument_type(i);
342
if (type == &ffi_type_pointer) {
343
if (*src) {
344
stack->push((intptr_t) src);
345
*(dst++) = stack->sp();
346
}
347
else {
348
*(dst++) = src;
349
}
350
src--;
351
}
352
else if (type->size == 4) {
353
*(dst++) = src--;
354
}
355
else if (type->size == 8) {
356
src--;
357
*(dst++) = src--;
358
}
359
else {
360
ShouldNotReachHere();
361
}
362
}
363
}
364
365
// Set up the Java frame anchor
366
thread->set_last_Java_frame();
367
368
// Change the thread state to _thread_in_native
369
ThreadStateTransition::transition_from_java(thread, _thread_in_native);
370
371
// Make the call
372
intptr_t result[4 - LogBytesPerWord];
373
ffi_call(handler->cif(), (void (*)()) function, result, arguments);
374
375
// Change the thread state back to _thread_in_Java.
376
// ThreadStateTransition::transition_from_native() cannot be used
377
// here because it does not check for asynchronous exceptions.
378
// We have to manage the transition ourself.
379
thread->set_thread_state(_thread_in_native_trans);
380
381
// Make sure new state is visible in the GC thread
382
if (os::is_MP()) {
383
if (UseMembar) {
384
OrderAccess::fence();
385
}
386
else {
387
InterfaceSupport::serialize_memory(thread);
388
}
389
}
390
391
// Handle safepoint operations, pending suspend requests,
392
// and pending asynchronous exceptions.
393
if (SafepointSynchronize::do_call_back() ||
394
thread->has_special_condition_for_native_trans()) {
395
JavaThread::check_special_condition_for_native_trans(thread);
396
CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops());
397
}
398
399
// Finally we can change the thread state to _thread_in_Java.
400
thread->set_thread_state(_thread_in_Java);
401
fixup_after_potential_safepoint();
402
403
// Clear the frame anchor
404
thread->reset_last_Java_frame();
405
406
// If the result was an oop then unbox it and store it in
407
// oop_temp where the garbage collector can see it before
408
// we release the handle it might be protected by.
409
if (handler->result_type() == &ffi_type_pointer) {
410
if (result[0] == 0) {
411
istate->set_oop_temp(NULL);
412
} else {
413
jobject handle = reinterpret_cast<jobject>(result[0]);
414
istate->set_oop_temp(JNIHandles::resolve(handle));
415
}
416
}
417
418
// Reset handle block
419
thread->active_handles()->clear();
420
421
unlock_unwind_and_return:
422
423
// Unlock if necessary
424
if (monitor) {
425
BasicLock *lock = monitor->lock();
426
markOop header = lock->displaced_header();
427
oop rcvr = monitor->obj();
428
monitor->set_obj(NULL);
429
430
if (header != NULL) {
431
if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) {
432
monitor->set_obj(rcvr); {
433
HandleMark hm(thread);
434
CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor));
435
}
436
}
437
}
438
}
439
440
unwind_and_return:
441
442
// Unwind the current activation
443
thread->pop_zero_frame();
444
445
// Pop our parameters
446
stack->set_sp(stack->sp() + method->size_of_parameters());
447
448
// Push our result
449
if (!HAS_PENDING_EXCEPTION) {
450
BasicType type = method->result_type();
451
stack->set_sp(stack->sp() - type2size[type]);
452
453
switch (type) {
454
case T_VOID:
455
break;
456
457
case T_BOOLEAN:
458
#ifndef VM_LITTLE_ENDIAN
459
result[0] <<= (BitsPerWord - BitsPerByte);
460
#endif
461
SET_LOCALS_INT(*(jboolean *) result != 0, 0);
462
break;
463
464
case T_CHAR:
465
#ifndef VM_LITTLE_ENDIAN
466
result[0] <<= (BitsPerWord - BitsPerShort);
467
#endif
468
SET_LOCALS_INT(*(jchar *) result, 0);
469
break;
470
471
case T_BYTE:
472
#ifndef VM_LITTLE_ENDIAN
473
result[0] <<= (BitsPerWord - BitsPerByte);
474
#endif
475
SET_LOCALS_INT(*(jbyte *) result, 0);
476
break;
477
478
case T_SHORT:
479
#ifndef VM_LITTLE_ENDIAN
480
result[0] <<= (BitsPerWord - BitsPerShort);
481
#endif
482
SET_LOCALS_INT(*(jshort *) result, 0);
483
break;
484
485
case T_INT:
486
#ifndef VM_LITTLE_ENDIAN
487
result[0] <<= (BitsPerWord - BitsPerInt);
488
#endif
489
SET_LOCALS_INT(*(jint *) result, 0);
490
break;
491
492
case T_LONG:
493
SET_LOCALS_LONG(*(jlong *) result, 0);
494
break;
495
496
case T_FLOAT:
497
SET_LOCALS_FLOAT(*(jfloat *) result, 0);
498
break;
499
500
case T_DOUBLE:
501
SET_LOCALS_DOUBLE(*(jdouble *) result, 0);
502
break;
503
504
case T_OBJECT:
505
case T_ARRAY:
506
SET_LOCALS_OBJECT(istate->oop_temp(), 0);
507
break;
508
509
default:
510
ShouldNotReachHere();
511
}
512
}
513
514
// No deoptimized frames on the stack
515
return 0;
516
}
517
518
int CppInterpreter::accessor_entry(Method* method, intptr_t UNUSED, TRAPS) {
519
JavaThread *thread = (JavaThread *) THREAD;
520
ZeroStack *stack = thread->zero_stack();
521
intptr_t *locals = stack->sp();
522
523
// Drop into the slow path if we need a safepoint check
524
if (SafepointSynchronize::do_call_back()) {
525
return normal_entry(method, 0, THREAD);
526
}
527
528
// Load the object pointer and drop into the slow path
529
// if we have a NullPointerException
530
oop object = LOCALS_OBJECT(0);
531
if (object == NULL) {
532
return normal_entry(method, 0, THREAD);
533
}
534
535
// Read the field index from the bytecode, which looks like this:
536
// 0: aload_0
537
// 1: getfield
538
// 2: index
539
// 3: index
540
// 4: ireturn/areturn
541
// NB this is not raw bytecode: index is in machine order
542
u1 *code = method->code_base();
543
assert(code[0] == Bytecodes::_aload_0 &&
544
code[1] == Bytecodes::_getfield &&
545
(code[4] == Bytecodes::_ireturn ||
546
code[4] == Bytecodes::_areturn), "should do");
547
u2 index = Bytes::get_native_u2(&code[2]);
548
549
// Get the entry from the constant pool cache, and drop into
550
// the slow path if it has not been resolved
551
ConstantPoolCache* cache = method->constants()->cache();
552
ConstantPoolCacheEntry* entry = cache->entry_at(index);
553
if (!entry->is_resolved(Bytecodes::_getfield)) {
554
return normal_entry(method, 0, THREAD);
555
}
556
557
// Get the result and push it onto the stack
558
switch (entry->flag_state()) {
559
case ltos:
560
case dtos:
561
stack->overflow_check(1, CHECK_0);
562
stack->alloc(wordSize);
563
break;
564
}
565
if (entry->is_volatile()) {
566
switch (entry->flag_state()) {
567
case ctos:
568
SET_LOCALS_INT(object->char_field_acquire(entry->f2_as_index()), 0);
569
break;
570
571
case btos:
572
case ztos:
573
SET_LOCALS_INT(object->byte_field_acquire(entry->f2_as_index()), 0);
574
break;
575
576
case stos:
577
SET_LOCALS_INT(object->short_field_acquire(entry->f2_as_index()), 0);
578
break;
579
580
case itos:
581
SET_LOCALS_INT(object->int_field_acquire(entry->f2_as_index()), 0);
582
break;
583
584
case ltos:
585
SET_LOCALS_LONG(object->long_field_acquire(entry->f2_as_index()), 0);
586
break;
587
588
case ftos:
589
SET_LOCALS_FLOAT(object->float_field_acquire(entry->f2_as_index()), 0);
590
break;
591
592
case dtos:
593
SET_LOCALS_DOUBLE(object->double_field_acquire(entry->f2_as_index()), 0);
594
break;
595
596
case atos:
597
SET_LOCALS_OBJECT(object->obj_field_acquire(entry->f2_as_index()), 0);
598
break;
599
600
default:
601
ShouldNotReachHere();
602
}
603
}
604
else {
605
switch (entry->flag_state()) {
606
case ctos:
607
SET_LOCALS_INT(object->char_field(entry->f2_as_index()), 0);
608
break;
609
610
case btos:
611
case ztos:
612
SET_LOCALS_INT(object->byte_field(entry->f2_as_index()), 0);
613
break;
614
615
case stos:
616
SET_LOCALS_INT(object->short_field(entry->f2_as_index()), 0);
617
break;
618
619
case itos:
620
SET_LOCALS_INT(object->int_field(entry->f2_as_index()), 0);
621
break;
622
623
case ltos:
624
SET_LOCALS_LONG(object->long_field(entry->f2_as_index()), 0);
625
break;
626
627
case ftos:
628
SET_LOCALS_FLOAT(object->float_field(entry->f2_as_index()), 0);
629
break;
630
631
case dtos:
632
SET_LOCALS_DOUBLE(object->double_field(entry->f2_as_index()), 0);
633
break;
634
635
case atos:
636
SET_LOCALS_OBJECT(object->obj_field(entry->f2_as_index()), 0);
637
break;
638
639
default:
640
ShouldNotReachHere();
641
}
642
}
643
644
// No deoptimized frames on the stack
645
return 0;
646
}
647
648
int CppInterpreter::empty_entry(Method* method, intptr_t UNUSED, TRAPS) {
649
JavaThread *thread = (JavaThread *) THREAD;
650
ZeroStack *stack = thread->zero_stack();
651
652
// Drop into the slow path if we need a safepoint check
653
if (SafepointSynchronize::do_call_back()) {
654
return normal_entry(method, 0, THREAD);
655
}
656
657
// Pop our parameters
658
stack->set_sp(stack->sp() + method->size_of_parameters());
659
660
// No deoptimized frames on the stack
661
return 0;
662
}
663
664
// The new slots will be inserted before slot insert_before.
665
// Slots < insert_before will have the same slot number after the insert.
666
// Slots >= insert_before will become old_slot + num_slots.
667
void CppInterpreter::insert_vmslots(int insert_before, int num_slots, TRAPS) {
668
JavaThread *thread = (JavaThread *) THREAD;
669
ZeroStack *stack = thread->zero_stack();
670
671
// Allocate the space
672
stack->overflow_check(num_slots, CHECK);
673
stack->alloc(num_slots * wordSize);
674
intptr_t *vmslots = stack->sp();
675
676
// Shuffle everything up
677
for (int i = 0; i < insert_before; i++)
678
SET_VMSLOTS_SLOT(VMSLOTS_SLOT(i + num_slots), i);
679
}
680
681
void CppInterpreter::remove_vmslots(int first_slot, int num_slots, TRAPS) {
682
JavaThread *thread = (JavaThread *) THREAD;
683
ZeroStack *stack = thread->zero_stack();
684
intptr_t *vmslots = stack->sp();
685
686
// Move everything down
687
for (int i = first_slot - 1; i >= 0; i--)
688
SET_VMSLOTS_SLOT(VMSLOTS_SLOT(i), i + num_slots);
689
690
// Deallocate the space
691
stack->set_sp(stack->sp() + num_slots);
692
}
693
694
BasicType CppInterpreter::result_type_of_handle(oop method_handle) {
695
oop method_type = java_lang_invoke_MethodHandle::type(method_handle);
696
oop return_type = java_lang_invoke_MethodType::rtype(method_type);
697
return java_lang_Class::as_BasicType(return_type, (Klass* *) NULL);
698
}
699
700
intptr_t* CppInterpreter::calculate_unwind_sp(ZeroStack* stack,
701
oop method_handle) {
702
oop method_type = java_lang_invoke_MethodHandle::type(method_handle);
703
int argument_slots = java_lang_invoke_MethodType::ptype_slot_count(method_type);
704
705
return stack->sp() + argument_slots;
706
}
707
708
IRT_ENTRY(void, CppInterpreter::throw_exception(JavaThread* thread,
709
Symbol* name,
710
char* message))
711
THROW_MSG(name, message);
712
IRT_END
713
714
InterpreterFrame *InterpreterFrame::build(Method* const method, TRAPS) {
715
JavaThread *thread = (JavaThread *) THREAD;
716
ZeroStack *stack = thread->zero_stack();
717
718
// Calculate the size of the frame we'll build, including
719
// any adjustments to the caller's frame that we'll make.
720
int extra_locals = 0;
721
int monitor_words = 0;
722
int stack_words = 0;
723
724
if (!method->is_native()) {
725
extra_locals = method->max_locals() - method->size_of_parameters();
726
stack_words = method->max_stack();
727
}
728
if (method->is_synchronized()) {
729
monitor_words = frame::interpreter_frame_monitor_size();
730
}
731
stack->overflow_check(
732
extra_locals + header_words + monitor_words + stack_words, CHECK_NULL);
733
734
// Adjust the caller's stack frame to accomodate any additional
735
// local variables we have contiguously with our parameters.
736
for (int i = 0; i < extra_locals; i++)
737
stack->push(0);
738
739
intptr_t *locals;
740
if (method->is_native())
741
locals = stack->sp() + (method->size_of_parameters() - 1);
742
else
743
locals = stack->sp() + (method->max_locals() - 1);
744
745
stack->push(0); // next_frame, filled in later
746
intptr_t *fp = stack->sp();
747
assert(fp - stack->sp() == next_frame_off, "should be");
748
749
stack->push(INTERPRETER_FRAME);
750
assert(fp - stack->sp() == frame_type_off, "should be");
751
752
interpreterState istate =
753
(interpreterState) stack->alloc(sizeof(BytecodeInterpreter));
754
assert(fp - stack->sp() == istate_off, "should be");
755
756
istate->set_locals(locals);
757
istate->set_method(method);
758
istate->set_self_link(istate);
759
istate->set_prev_link(NULL);
760
istate->set_thread(thread);
761
istate->set_bcp(method->is_native() ? NULL : method->code_base());
762
istate->set_constants(method->constants()->cache());
763
istate->set_msg(BytecodeInterpreter::method_entry);
764
istate->set_oop_temp(NULL);
765
istate->set_mdx(NULL);
766
istate->set_callee(NULL);
767
768
istate->set_monitor_base((BasicObjectLock *) stack->sp());
769
if (method->is_synchronized()) {
770
BasicObjectLock *monitor =
771
(BasicObjectLock *) stack->alloc(monitor_words * wordSize);
772
oop object;
773
if (method->is_static())
774
object = method->constants()->pool_holder()->java_mirror();
775
else
776
object = (oop) (void*)locals[0];
777
monitor->set_obj(object);
778
}
779
780
istate->set_stack_base(stack->sp());
781
istate->set_stack(stack->sp() - 1);
782
if (stack_words)
783
stack->alloc(stack_words * wordSize);
784
istate->set_stack_limit(stack->sp() - 1);
785
786
return (InterpreterFrame *) fp;
787
}
788
789
int AbstractInterpreter::BasicType_as_index(BasicType type) {
790
int i = 0;
791
switch (type) {
792
case T_BOOLEAN: i = 0; break;
793
case T_CHAR : i = 1; break;
794
case T_BYTE : i = 2; break;
795
case T_SHORT : i = 3; break;
796
case T_INT : i = 4; break;
797
case T_LONG : i = 5; break;
798
case T_VOID : i = 6; break;
799
case T_FLOAT : i = 7; break;
800
case T_DOUBLE : i = 8; break;
801
case T_OBJECT : i = 9; break;
802
case T_ARRAY : i = 9; break;
803
default : ShouldNotReachHere();
804
}
805
assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers,
806
"index out of bounds");
807
return i;
808
}
809
810
address InterpreterGenerator::generate_empty_entry() {
811
if (!UseFastEmptyMethods)
812
return NULL;
813
814
return generate_entry((address) CppInterpreter::empty_entry);
815
}
816
817
address InterpreterGenerator::generate_accessor_entry() {
818
if (!UseFastAccessorMethods)
819
return NULL;
820
821
return generate_entry((address) CppInterpreter::accessor_entry);
822
}
823
824
address InterpreterGenerator::generate_Reference_get_entry(void) {
825
#if INCLUDE_ALL_GCS
826
if (UseG1GC) {
827
// We need to generate have a routine that generates code to:
828
// * load the value in the referent field
829
// * passes that value to the pre-barrier.
830
//
831
// In the case of G1 this will record the value of the
832
// referent in an SATB buffer if marking is active.
833
// This will cause concurrent marking to mark the referent
834
// field as live.
835
Unimplemented();
836
}
837
#endif // INCLUDE_ALL_GCS
838
839
// If G1 is not enabled then attempt to go through the accessor entry point
840
// Reference.get is an accessor
841
return generate_accessor_entry();
842
}
843
844
address InterpreterGenerator::generate_native_entry(bool synchronized) {
845
assert(synchronized == false, "should be");
846
847
return generate_entry((address) CppInterpreter::native_entry);
848
}
849
850
address InterpreterGenerator::generate_normal_entry(bool synchronized) {
851
assert(synchronized == false, "should be");
852
853
return generate_entry((address) CppInterpreter::normal_entry);
854
}
855
856
address AbstractInterpreterGenerator::generate_method_entry(
857
AbstractInterpreter::MethodKind kind) {
858
address entry_point = NULL;
859
860
switch (kind) {
861
case Interpreter::zerolocals:
862
case Interpreter::zerolocals_synchronized:
863
break;
864
865
case Interpreter::native:
866
entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false);
867
break;
868
869
case Interpreter::native_synchronized:
870
entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false);
871
break;
872
873
case Interpreter::empty:
874
entry_point = ((InterpreterGenerator*) this)->generate_empty_entry();
875
break;
876
877
case Interpreter::accessor:
878
entry_point = ((InterpreterGenerator*) this)->generate_accessor_entry();
879
break;
880
881
case Interpreter::abstract:
882
entry_point = ((InterpreterGenerator*) this)->generate_abstract_entry();
883
break;
884
885
case Interpreter::java_lang_math_sin:
886
case Interpreter::java_lang_math_cos:
887
case Interpreter::java_lang_math_tan:
888
case Interpreter::java_lang_math_abs:
889
case Interpreter::java_lang_math_log:
890
case Interpreter::java_lang_math_log10:
891
case Interpreter::java_lang_math_sqrt:
892
case Interpreter::java_lang_math_pow:
893
case Interpreter::java_lang_math_exp:
894
entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind);
895
break;
896
897
case Interpreter::java_lang_ref_reference_get:
898
entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry();
899
break;
900
901
default:
902
ShouldNotReachHere();
903
}
904
905
if (entry_point == NULL)
906
entry_point = ((InterpreterGenerator*) this)->generate_normal_entry(false);
907
908
return entry_point;
909
}
910
911
InterpreterGenerator::InterpreterGenerator(StubQueue* code)
912
: CppInterpreterGenerator(code) {
913
generate_all();
914
}
915
916
// Deoptimization helpers
917
918
InterpreterFrame *InterpreterFrame::build(int size, TRAPS) {
919
ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack();
920
921
int size_in_words = size >> LogBytesPerWord;
922
assert(size_in_words * wordSize == size, "unaligned");
923
assert(size_in_words >= header_words, "too small");
924
stack->overflow_check(size_in_words, CHECK_NULL);
925
926
stack->push(0); // next_frame, filled in later
927
intptr_t *fp = stack->sp();
928
assert(fp - stack->sp() == next_frame_off, "should be");
929
930
stack->push(INTERPRETER_FRAME);
931
assert(fp - stack->sp() == frame_type_off, "should be");
932
933
interpreterState istate =
934
(interpreterState) stack->alloc(sizeof(BytecodeInterpreter));
935
assert(fp - stack->sp() == istate_off, "should be");
936
istate->set_self_link(NULL); // mark invalid
937
938
stack->alloc((size_in_words - header_words) * wordSize);
939
940
return (InterpreterFrame *) fp;
941
}
942
943
int AbstractInterpreter::size_activation(int max_stack,
944
int tempcount,
945
int extra_args,
946
int moncount,
947
int callee_param_count,
948
int callee_locals,
949
bool is_top_frame) {
950
int header_words = InterpreterFrame::header_words;
951
int monitor_words = moncount * frame::interpreter_frame_monitor_size();
952
int stack_words = is_top_frame ? max_stack : tempcount;
953
int callee_extra_locals = callee_locals - callee_param_count;
954
955
return header_words + monitor_words + stack_words + callee_extra_locals;
956
}
957
958
void AbstractInterpreter::layout_activation(Method* method,
959
int tempcount,
960
int popframe_extra_args,
961
int moncount,
962
int caller_actual_parameters,
963
int callee_param_count,
964
int callee_locals,
965
frame* caller,
966
frame* interpreter_frame,
967
bool is_top_frame,
968
bool is_bottom_frame) {
969
assert(popframe_extra_args == 0, "what to do?");
970
assert(!is_top_frame || (!callee_locals && !callee_param_count),
971
"top frame should have no caller");
972
973
// This code must exactly match what InterpreterFrame::build
974
// does (the full InterpreterFrame::build, that is, not the
975
// one that creates empty frames for the deoptimizer).
976
//
977
// interpreter_frame will be filled in. It's size is determined by
978
// a previous call to the size_activation() method,
979
//
980
// Note that tempcount is the current size of the expression
981
// stack. For top most frames we will allocate a full sized
982
// expression stack and not the trimmed version that non-top
983
// frames have.
984
985
int monitor_words = moncount * frame::interpreter_frame_monitor_size();
986
intptr_t *locals = interpreter_frame->fp() + method->max_locals();
987
interpreterState istate = interpreter_frame->get_interpreterState();
988
intptr_t *monitor_base = (intptr_t*) istate;
989
intptr_t *stack_base = monitor_base - monitor_words;
990
intptr_t *stack = stack_base - tempcount - 1;
991
992
BytecodeInterpreter::layout_interpreterState(istate,
993
caller,
994
NULL,
995
method,
996
locals,
997
stack,
998
stack_base,
999
monitor_base,
1000
NULL,
1001
is_top_frame);
1002
}
1003
1004
void BytecodeInterpreter::layout_interpreterState(interpreterState istate,
1005
frame* caller,
1006
frame* current,
1007
Method* method,
1008
intptr_t* locals,
1009
intptr_t* stack,
1010
intptr_t* stack_base,
1011
intptr_t* monitor_base,
1012
intptr_t* frame_bottom,
1013
bool is_top_frame) {
1014
istate->set_locals(locals);
1015
istate->set_method(method);
1016
istate->set_self_link(istate);
1017
istate->set_prev_link(NULL);
1018
// thread will be set by a hacky repurposing of frame::patch_pc()
1019
// bcp will be set by vframeArrayElement::unpack_on_stack()
1020
istate->set_constants(method->constants()->cache());
1021
istate->set_msg(BytecodeInterpreter::method_resume);
1022
istate->set_bcp_advance(0);
1023
istate->set_oop_temp(NULL);
1024
istate->set_mdx(NULL);
1025
if (caller->is_interpreted_frame()) {
1026
interpreterState prev = caller->get_interpreterState();
1027
prev->set_callee(method);
1028
if (*prev->bcp() == Bytecodes::_invokeinterface)
1029
prev->set_bcp_advance(5);
1030
else
1031
prev->set_bcp_advance(3);
1032
}
1033
istate->set_callee(NULL);
1034
istate->set_monitor_base((BasicObjectLock *) monitor_base);
1035
istate->set_stack_base(stack_base);
1036
istate->set_stack(stack);
1037
istate->set_stack_limit(stack_base - method->max_stack() - 1);
1038
}
1039
1040
address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) {
1041
ShouldNotCallThis();
1042
return NULL;
1043
}
1044
1045
address CppInterpreter::deopt_entry(TosState state, int length) {
1046
return NULL;
1047
}
1048
1049
// Helper for (runtime) stack overflow checks
1050
1051
int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
1052
return 0;
1053
}
1054
1055
// Helper for figuring out if frames are interpreter frames
1056
1057
bool CppInterpreter::contains(address pc) {
1058
return false; // make frame::print_value_on work
1059
}
1060
1061
// Result handlers and convertors
1062
1063
address CppInterpreterGenerator::generate_result_handler_for(
1064
BasicType type) {
1065
assembler()->advance(1);
1066
return ShouldNotCallThisStub();
1067
}
1068
1069
address CppInterpreterGenerator::generate_tosca_to_stack_converter(
1070
BasicType type) {
1071
assembler()->advance(1);
1072
return ShouldNotCallThisStub();
1073
}
1074
1075
address CppInterpreterGenerator::generate_stack_to_stack_converter(
1076
BasicType type) {
1077
assembler()->advance(1);
1078
return ShouldNotCallThisStub();
1079
}
1080
1081
address CppInterpreterGenerator::generate_stack_to_native_abi_converter(
1082
BasicType type) {
1083
assembler()->advance(1);
1084
return ShouldNotCallThisStub();
1085
}
1086
1087
#endif // CC_INTERP
1088
1089