Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp
66644 views
1
/*
2
* Copyright (c) 2002, 2021, 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
// no precompiled headers
26
#include "jvm_io.h"
27
#include "classfile/javaClasses.hpp"
28
#include "classfile/vmSymbols.hpp"
29
#include "gc/shared/collectedHeap.hpp"
30
#include "gc/shared/threadLocalAllocBuffer.inline.hpp"
31
#include "gc/shared/tlab_globals.hpp"
32
#include "interpreter/bytecodeHistogram.hpp"
33
#include "interpreter/zero/bytecodeInterpreter.inline.hpp"
34
#include "interpreter/interpreter.hpp"
35
#include "interpreter/interpreterRuntime.hpp"
36
#include "logging/log.hpp"
37
#include "memory/resourceArea.hpp"
38
#include "memory/universe.hpp"
39
#include "oops/constantPool.inline.hpp"
40
#include "oops/cpCache.inline.hpp"
41
#include "oops/instanceKlass.inline.hpp"
42
#include "oops/klass.inline.hpp"
43
#include "oops/method.inline.hpp"
44
#include "oops/methodCounters.hpp"
45
#include "oops/objArrayKlass.hpp"
46
#include "oops/objArrayOop.inline.hpp"
47
#include "oops/oop.inline.hpp"
48
#include "oops/typeArrayOop.inline.hpp"
49
#include "prims/jvmtiExport.hpp"
50
#include "prims/jvmtiThreadState.hpp"
51
#include "runtime/atomic.hpp"
52
#include "runtime/frame.inline.hpp"
53
#include "runtime/handles.inline.hpp"
54
#include "runtime/interfaceSupport.inline.hpp"
55
#include "runtime/orderAccess.hpp"
56
#include "runtime/sharedRuntime.hpp"
57
#include "runtime/threadCritical.hpp"
58
#include "utilities/debug.hpp"
59
#include "utilities/exceptions.hpp"
60
#include "utilities/macros.hpp"
61
62
// no precompiled headers
63
64
/*
65
* USELABELS - If using GCC, then use labels for the opcode dispatching
66
* rather -then a switch statement. This improves performance because it
67
* gives us the opportunity to have the instructions that calculate the
68
* next opcode to jump to be intermixed with the rest of the instructions
69
* that implement the opcode (see UPDATE_PC_AND_TOS_AND_CONTINUE macro).
70
*/
71
#undef USELABELS
72
#ifdef __GNUC__
73
/*
74
ASSERT signifies debugging. It is much easier to step thru bytecodes if we
75
don't use the computed goto approach.
76
*/
77
#ifndef ASSERT
78
#define USELABELS
79
#endif
80
#endif
81
82
#undef CASE
83
#ifdef USELABELS
84
#define CASE(opcode) opc ## opcode
85
#define DEFAULT opc_default
86
#else
87
#define CASE(opcode) case Bytecodes:: opcode
88
#define DEFAULT default
89
#endif
90
91
/*
92
* PREFETCH_OPCCODE - Some compilers do better if you prefetch the next
93
* opcode before going back to the top of the while loop, rather then having
94
* the top of the while loop handle it. This provides a better opportunity
95
* for instruction scheduling. Some compilers just do this prefetch
96
* automatically. Some actually end up with worse performance if you
97
* force the prefetch. Solaris gcc seems to do better, but cc does worse.
98
*/
99
#undef PREFETCH_OPCCODE
100
#define PREFETCH_OPCCODE
101
102
/*
103
Interpreter safepoint: it is expected that the interpreter will have no live
104
handles of its own creation live at an interpreter safepoint. Therefore we
105
run a HandleMarkCleaner and trash all handles allocated in the call chain
106
since the JavaCalls::call_helper invocation that initiated the chain.
107
There really shouldn't be any handles remaining to trash but this is cheap
108
in relation to a safepoint.
109
*/
110
#define RETURN_SAFEPOINT \
111
if (SafepointMechanism::should_process(THREAD)) { \
112
HandleMarkCleaner __hmc(THREAD); \
113
CALL_VM(SafepointMechanism::process_if_requested_with_exit_check(THREAD, true /* check asyncs */), \
114
handle_exception); \
115
} \
116
117
/*
118
* VM_JAVA_ERROR - Macro for throwing a java exception from
119
* the interpreter loop. Should really be a CALL_VM but there
120
* is no entry point to do the transition to vm so we just
121
* do it by hand here.
122
*/
123
#define VM_JAVA_ERROR_NO_JUMP(name, msg) \
124
DECACHE_STATE(); \
125
SET_LAST_JAVA_FRAME(); \
126
{ \
127
ThreadInVMfromJava trans(THREAD); \
128
Exceptions::_throw_msg(THREAD, __FILE__, __LINE__, name, msg); \
129
} \
130
RESET_LAST_JAVA_FRAME(); \
131
CACHE_STATE();
132
133
// Normal throw of a java error.
134
#define VM_JAVA_ERROR(name, msg) \
135
VM_JAVA_ERROR_NO_JUMP(name, msg) \
136
goto handle_exception;
137
138
#ifdef PRODUCT
139
#define DO_UPDATE_INSTRUCTION_COUNT(opcode)
140
#else
141
#define DO_UPDATE_INSTRUCTION_COUNT(opcode) \
142
{ \
143
if (PrintBytecodeHistogram) { \
144
BytecodeHistogram::_counters[(Bytecodes::Code)opcode]++; \
145
} \
146
if (CountBytecodes || TraceBytecodes || StopInterpreterAt > 0) { \
147
BytecodeCounter::_counter_value++; \
148
if (StopInterpreterAt == BytecodeCounter::_counter_value) { \
149
os::breakpoint(); \
150
} \
151
if (TraceBytecodes) { \
152
CALL_VM((void)InterpreterRuntime::trace_bytecode(THREAD, 0, \
153
topOfStack[Interpreter::expr_index_at(1)], \
154
topOfStack[Interpreter::expr_index_at(2)]), \
155
handle_exception); \
156
} \
157
} \
158
}
159
#endif
160
161
#undef DEBUGGER_SINGLE_STEP_NOTIFY
162
#if INCLUDE_JVMTI
163
/* NOTE: (kbr) This macro must be called AFTER the PC has been
164
incremented. JvmtiExport::at_single_stepping_point() may cause a
165
breakpoint opcode to get inserted at the current PC to allow the
166
debugger to coalesce single-step events.
167
168
As a result if we call at_single_stepping_point() we refetch opcode
169
to get the current opcode. This will override any other prefetching
170
that might have occurred.
171
*/
172
#define DEBUGGER_SINGLE_STEP_NOTIFY() \
173
{ \
174
if (JVMTI_ENABLED && JvmtiExport::should_post_single_step()) { \
175
DECACHE_STATE(); \
176
SET_LAST_JAVA_FRAME(); \
177
ThreadInVMfromJava trans(THREAD); \
178
JvmtiExport::at_single_stepping_point(THREAD, \
179
istate->method(), \
180
pc); \
181
RESET_LAST_JAVA_FRAME(); \
182
CACHE_STATE(); \
183
if (THREAD->has_pending_popframe() && \
184
!THREAD->pop_frame_in_process()) { \
185
goto handle_Pop_Frame; \
186
} \
187
if (THREAD->jvmti_thread_state() && \
188
THREAD->jvmti_thread_state()->is_earlyret_pending()) { \
189
goto handle_Early_Return; \
190
} \
191
opcode = *pc; \
192
} \
193
}
194
#else
195
#define DEBUGGER_SINGLE_STEP_NOTIFY()
196
#endif // INCLUDE_JVMTI
197
198
/*
199
* CONTINUE - Macro for executing the next opcode.
200
*/
201
#undef CONTINUE
202
#ifdef USELABELS
203
// Have to do this dispatch this way in C++ because otherwise gcc complains about crossing an
204
// initialization (which is is the initialization of the table pointer...)
205
#define DISPATCH(opcode) goto *(void*)dispatch_table[opcode]
206
#define CONTINUE { \
207
opcode = *pc; \
208
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
209
DEBUGGER_SINGLE_STEP_NOTIFY(); \
210
DISPATCH(opcode); \
211
}
212
#else
213
#ifdef PREFETCH_OPCCODE
214
#define CONTINUE { \
215
opcode = *pc; \
216
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
217
DEBUGGER_SINGLE_STEP_NOTIFY(); \
218
continue; \
219
}
220
#else
221
#define CONTINUE { \
222
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
223
DEBUGGER_SINGLE_STEP_NOTIFY(); \
224
continue; \
225
}
226
#endif
227
#endif
228
229
230
#define UPDATE_PC(opsize) {pc += opsize; }
231
/*
232
* UPDATE_PC_AND_TOS - Macro for updating the pc and topOfStack.
233
*/
234
#undef UPDATE_PC_AND_TOS
235
#define UPDATE_PC_AND_TOS(opsize, stack) \
236
{pc += opsize; MORE_STACK(stack); }
237
238
/*
239
* UPDATE_PC_AND_TOS_AND_CONTINUE - Macro for updating the pc and topOfStack,
240
* and executing the next opcode. It's somewhat similar to the combination
241
* of UPDATE_PC_AND_TOS and CONTINUE, but with some minor optimizations.
242
*/
243
#undef UPDATE_PC_AND_TOS_AND_CONTINUE
244
#ifdef USELABELS
245
#define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) { \
246
pc += opsize; opcode = *pc; MORE_STACK(stack); \
247
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
248
DEBUGGER_SINGLE_STEP_NOTIFY(); \
249
DISPATCH(opcode); \
250
}
251
252
#define UPDATE_PC_AND_CONTINUE(opsize) { \
253
pc += opsize; opcode = *pc; \
254
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
255
DEBUGGER_SINGLE_STEP_NOTIFY(); \
256
DISPATCH(opcode); \
257
}
258
#else
259
#ifdef PREFETCH_OPCCODE
260
#define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) { \
261
pc += opsize; opcode = *pc; MORE_STACK(stack); \
262
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
263
DEBUGGER_SINGLE_STEP_NOTIFY(); \
264
goto do_continue; \
265
}
266
267
#define UPDATE_PC_AND_CONTINUE(opsize) { \
268
pc += opsize; opcode = *pc; \
269
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
270
DEBUGGER_SINGLE_STEP_NOTIFY(); \
271
goto do_continue; \
272
}
273
#else
274
#define UPDATE_PC_AND_TOS_AND_CONTINUE(opsize, stack) { \
275
pc += opsize; MORE_STACK(stack); \
276
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
277
DEBUGGER_SINGLE_STEP_NOTIFY(); \
278
goto do_continue; \
279
}
280
281
#define UPDATE_PC_AND_CONTINUE(opsize) { \
282
pc += opsize; \
283
DO_UPDATE_INSTRUCTION_COUNT(opcode); \
284
DEBUGGER_SINGLE_STEP_NOTIFY(); \
285
goto do_continue; \
286
}
287
#endif /* PREFETCH_OPCCODE */
288
#endif /* USELABELS */
289
290
// About to call a new method, update the save the adjusted pc and return to frame manager
291
#define UPDATE_PC_AND_RETURN(opsize) \
292
DECACHE_TOS(); \
293
istate->set_bcp(pc+opsize); \
294
return;
295
296
297
#define METHOD istate->method()
298
#define GET_METHOD_COUNTERS(res)
299
#define DO_BACKEDGE_CHECKS(skip, branch_pc)
300
301
/*
302
* For those opcodes that need to have a GC point on a backwards branch
303
*/
304
305
/*
306
* Macros for caching and flushing the interpreter state. Some local
307
* variables need to be flushed out to the frame before we do certain
308
* things (like pushing frames or becomming gc safe) and some need to
309
* be recached later (like after popping a frame). We could use one
310
* macro to cache or decache everything, but this would be less then
311
* optimal because we don't always need to cache or decache everything
312
* because some things we know are already cached or decached.
313
*/
314
#undef DECACHE_TOS
315
#undef CACHE_TOS
316
#undef CACHE_PREV_TOS
317
#define DECACHE_TOS() istate->set_stack(topOfStack);
318
319
#define CACHE_TOS() topOfStack = (intptr_t *)istate->stack();
320
321
#undef DECACHE_PC
322
#undef CACHE_PC
323
#define DECACHE_PC() istate->set_bcp(pc);
324
#define CACHE_PC() pc = istate->bcp();
325
#define CACHE_CP() cp = istate->constants();
326
#define CACHE_LOCALS() locals = istate->locals();
327
#undef CACHE_FRAME
328
#define CACHE_FRAME()
329
330
// BCI() returns the current bytecode-index.
331
#undef BCI
332
#define BCI() ((int)(intptr_t)(pc - (intptr_t)istate->method()->code_base()))
333
334
/*
335
* CHECK_NULL - Macro for throwing a NullPointerException if the object
336
* passed is a null ref.
337
* On some architectures/platforms it should be possible to do this implicitly
338
*/
339
#undef CHECK_NULL
340
#define CHECK_NULL(obj_) \
341
if ((obj_) == NULL) { \
342
VM_JAVA_ERROR(vmSymbols::java_lang_NullPointerException(), NULL); \
343
} \
344
VERIFY_OOP(obj_)
345
346
#define VMdoubleConstZero() 0.0
347
#define VMdoubleConstOne() 1.0
348
#define VMlongConstZero() (max_jlong-max_jlong)
349
#define VMlongConstOne() ((max_jlong-max_jlong)+1)
350
351
/*
352
* Alignment
353
*/
354
#define VMalignWordUp(val) (((uintptr_t)(val) + 3) & ~3)
355
356
// Decache the interpreter state that interpreter modifies directly (i.e. GC is indirect mod)
357
#define DECACHE_STATE() DECACHE_PC(); DECACHE_TOS();
358
359
// Reload interpreter state after calling the VM or a possible GC
360
#define CACHE_STATE() \
361
CACHE_TOS(); \
362
CACHE_PC(); \
363
CACHE_CP(); \
364
CACHE_LOCALS();
365
366
// Call the VM with last java frame only.
367
#define CALL_VM_NAKED_LJF(func) \
368
DECACHE_STATE(); \
369
SET_LAST_JAVA_FRAME(); \
370
func; \
371
RESET_LAST_JAVA_FRAME(); \
372
CACHE_STATE();
373
374
// Call the VM. Don't check for pending exceptions.
375
#define CALL_VM_NOCHECK(func) \
376
CALL_VM_NAKED_LJF(func) \
377
if (THREAD->has_pending_popframe() && \
378
!THREAD->pop_frame_in_process()) { \
379
goto handle_Pop_Frame; \
380
} \
381
if (THREAD->jvmti_thread_state() && \
382
THREAD->jvmti_thread_state()->is_earlyret_pending()) { \
383
goto handle_Early_Return; \
384
}
385
386
// Call the VM and check for pending exceptions
387
#define CALL_VM(func, label) { \
388
CALL_VM_NOCHECK(func); \
389
if (THREAD->has_pending_exception()) goto label; \
390
}
391
392
/*
393
* BytecodeInterpreter::run(interpreterState istate)
394
*
395
* The real deal. This is where byte codes actually get interpreted.
396
* Basically it's a big while loop that iterates until we return from
397
* the method passed in.
398
*/
399
400
// Instantiate two variants of the method for future linking.
401
template void BytecodeInterpreter::run<true>(interpreterState istate);
402
template void BytecodeInterpreter::run<false>(interpreterState istate);
403
404
template<bool JVMTI_ENABLED>
405
void BytecodeInterpreter::run(interpreterState istate) {
406
intptr_t* topOfStack = (intptr_t *)istate->stack(); /* access with STACK macros */
407
address pc = istate->bcp();
408
jubyte opcode;
409
intptr_t* locals = istate->locals();
410
ConstantPoolCache* cp = istate->constants(); // method()->constants()->cache()
411
#ifdef LOTS_OF_REGS
412
JavaThread* THREAD = istate->thread();
413
#else
414
#undef THREAD
415
#define THREAD istate->thread()
416
#endif
417
418
#ifdef ASSERT
419
assert(labs(istate->stack_base() - istate->stack_limit()) == (istate->method()->max_stack() + 1),
420
"Bad stack limit");
421
/* QQQ this should be a stack method so we don't know actual direction */
422
assert(topOfStack >= istate->stack_limit() && topOfStack < istate->stack_base(),
423
"Stack top out of range");
424
425
// Verify linkages.
426
interpreterState l = istate;
427
do {
428
assert(l == l->_self_link, "bad link");
429
l = l->_prev_link;
430
} while (l != NULL);
431
// Screwups with stack management usually cause us to overwrite istate
432
// save a copy so we can verify it.
433
interpreterState orig = istate;
434
#endif
435
436
#ifdef USELABELS
437
const static void* const opclabels_data[256] = {
438
/* 0x00 */ &&opc_nop, &&opc_aconst_null, &&opc_iconst_m1, &&opc_iconst_0,
439
/* 0x04 */ &&opc_iconst_1, &&opc_iconst_2, &&opc_iconst_3, &&opc_iconst_4,
440
/* 0x08 */ &&opc_iconst_5, &&opc_lconst_0, &&opc_lconst_1, &&opc_fconst_0,
441
/* 0x0C */ &&opc_fconst_1, &&opc_fconst_2, &&opc_dconst_0, &&opc_dconst_1,
442
443
/* 0x10 */ &&opc_bipush, &&opc_sipush, &&opc_ldc, &&opc_ldc_w,
444
/* 0x14 */ &&opc_ldc2_w, &&opc_iload, &&opc_lload, &&opc_fload,
445
/* 0x18 */ &&opc_dload, &&opc_aload, &&opc_iload_0, &&opc_iload_1,
446
/* 0x1C */ &&opc_iload_2, &&opc_iload_3, &&opc_lload_0, &&opc_lload_1,
447
448
/* 0x20 */ &&opc_lload_2, &&opc_lload_3, &&opc_fload_0, &&opc_fload_1,
449
/* 0x24 */ &&opc_fload_2, &&opc_fload_3, &&opc_dload_0, &&opc_dload_1,
450
/* 0x28 */ &&opc_dload_2, &&opc_dload_3, &&opc_aload_0, &&opc_aload_1,
451
/* 0x2C */ &&opc_aload_2, &&opc_aload_3, &&opc_iaload, &&opc_laload,
452
453
/* 0x30 */ &&opc_faload, &&opc_daload, &&opc_aaload, &&opc_baload,
454
/* 0x34 */ &&opc_caload, &&opc_saload, &&opc_istore, &&opc_lstore,
455
/* 0x38 */ &&opc_fstore, &&opc_dstore, &&opc_astore, &&opc_istore_0,
456
/* 0x3C */ &&opc_istore_1, &&opc_istore_2, &&opc_istore_3, &&opc_lstore_0,
457
458
/* 0x40 */ &&opc_lstore_1, &&opc_lstore_2, &&opc_lstore_3, &&opc_fstore_0,
459
/* 0x44 */ &&opc_fstore_1, &&opc_fstore_2, &&opc_fstore_3, &&opc_dstore_0,
460
/* 0x48 */ &&opc_dstore_1, &&opc_dstore_2, &&opc_dstore_3, &&opc_astore_0,
461
/* 0x4C */ &&opc_astore_1, &&opc_astore_2, &&opc_astore_3, &&opc_iastore,
462
463
/* 0x50 */ &&opc_lastore, &&opc_fastore, &&opc_dastore, &&opc_aastore,
464
/* 0x54 */ &&opc_bastore, &&opc_castore, &&opc_sastore, &&opc_pop,
465
/* 0x58 */ &&opc_pop2, &&opc_dup, &&opc_dup_x1, &&opc_dup_x2,
466
/* 0x5C */ &&opc_dup2, &&opc_dup2_x1, &&opc_dup2_x2, &&opc_swap,
467
468
/* 0x60 */ &&opc_iadd, &&opc_ladd, &&opc_fadd, &&opc_dadd,
469
/* 0x64 */ &&opc_isub, &&opc_lsub, &&opc_fsub, &&opc_dsub,
470
/* 0x68 */ &&opc_imul, &&opc_lmul, &&opc_fmul, &&opc_dmul,
471
/* 0x6C */ &&opc_idiv, &&opc_ldiv, &&opc_fdiv, &&opc_ddiv,
472
473
/* 0x70 */ &&opc_irem, &&opc_lrem, &&opc_frem, &&opc_drem,
474
/* 0x74 */ &&opc_ineg, &&opc_lneg, &&opc_fneg, &&opc_dneg,
475
/* 0x78 */ &&opc_ishl, &&opc_lshl, &&opc_ishr, &&opc_lshr,
476
/* 0x7C */ &&opc_iushr, &&opc_lushr, &&opc_iand, &&opc_land,
477
478
/* 0x80 */ &&opc_ior, &&opc_lor, &&opc_ixor, &&opc_lxor,
479
/* 0x84 */ &&opc_iinc, &&opc_i2l, &&opc_i2f, &&opc_i2d,
480
/* 0x88 */ &&opc_l2i, &&opc_l2f, &&opc_l2d, &&opc_f2i,
481
/* 0x8C */ &&opc_f2l, &&opc_f2d, &&opc_d2i, &&opc_d2l,
482
483
/* 0x90 */ &&opc_d2f, &&opc_i2b, &&opc_i2c, &&opc_i2s,
484
/* 0x94 */ &&opc_lcmp, &&opc_fcmpl, &&opc_fcmpg, &&opc_dcmpl,
485
/* 0x98 */ &&opc_dcmpg, &&opc_ifeq, &&opc_ifne, &&opc_iflt,
486
/* 0x9C */ &&opc_ifge, &&opc_ifgt, &&opc_ifle, &&opc_if_icmpeq,
487
488
/* 0xA0 */ &&opc_if_icmpne, &&opc_if_icmplt, &&opc_if_icmpge, &&opc_if_icmpgt,
489
/* 0xA4 */ &&opc_if_icmple, &&opc_if_acmpeq, &&opc_if_acmpne, &&opc_goto,
490
/* 0xA8 */ &&opc_jsr, &&opc_ret, &&opc_tableswitch, &&opc_lookupswitch,
491
/* 0xAC */ &&opc_ireturn, &&opc_lreturn, &&opc_freturn, &&opc_dreturn,
492
493
/* 0xB0 */ &&opc_areturn, &&opc_return, &&opc_getstatic, &&opc_putstatic,
494
/* 0xB4 */ &&opc_getfield, &&opc_putfield, &&opc_invokevirtual, &&opc_invokespecial,
495
/* 0xB8 */ &&opc_invokestatic, &&opc_invokeinterface, &&opc_invokedynamic, &&opc_new,
496
/* 0xBC */ &&opc_newarray, &&opc_anewarray, &&opc_arraylength, &&opc_athrow,
497
498
/* 0xC0 */ &&opc_checkcast, &&opc_instanceof, &&opc_monitorenter, &&opc_monitorexit,
499
/* 0xC4 */ &&opc_wide, &&opc_multianewarray, &&opc_ifnull, &&opc_ifnonnull,
500
/* 0xC8 */ &&opc_goto_w, &&opc_jsr_w, &&opc_breakpoint, &&opc_default,
501
/* 0xCC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
502
503
/* 0xD0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
504
/* 0xD4 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
505
/* 0xD8 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
506
/* 0xDC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
507
508
/* 0xE0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
509
/* 0xE4 */ &&opc_default, &&opc_default, &&opc_fast_aldc, &&opc_fast_aldc_w,
510
/* 0xE8 */ &&opc_return_register_finalizer,
511
&&opc_invokehandle, &&opc_default, &&opc_default,
512
/* 0xEC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
513
514
/* 0xF0 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
515
/* 0xF4 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
516
/* 0xF8 */ &&opc_default, &&opc_default, &&opc_default, &&opc_default,
517
/* 0xFC */ &&opc_default, &&opc_default, &&opc_default, &&opc_default
518
};
519
uintptr_t *dispatch_table = (uintptr_t*)&opclabels_data[0];
520
#endif /* USELABELS */
521
522
switch (istate->msg()) {
523
case initialize: {
524
ShouldNotCallThis();
525
return;
526
}
527
case method_entry: {
528
THREAD->set_do_not_unlock();
529
530
// Lock method if synchronized.
531
if (METHOD->is_synchronized()) {
532
// oop rcvr = locals[0].j.r;
533
oop rcvr;
534
if (METHOD->is_static()) {
535
rcvr = METHOD->constants()->pool_holder()->java_mirror();
536
} else {
537
rcvr = LOCALS_OBJECT(0);
538
VERIFY_OOP(rcvr);
539
}
540
541
// The initial monitor is ours for the taking.
542
// Monitor not filled in frame manager any longer as this caused race condition with biased locking.
543
BasicObjectLock* mon = &istate->monitor_base()[-1];
544
mon->set_obj(rcvr);
545
546
assert(!UseBiasedLocking, "Not implemented");
547
548
// Traditional lightweight locking.
549
markWord displaced = rcvr->mark().set_unlocked();
550
mon->lock()->set_displaced_header(displaced);
551
bool call_vm = UseHeavyMonitors;
552
if (call_vm || rcvr->cas_set_mark(markWord::from_pointer(mon), displaced) != displaced) {
553
// Is it simple recursive case?
554
if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
555
mon->lock()->set_displaced_header(markWord::from_pointer(NULL));
556
} else {
557
CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
558
}
559
}
560
}
561
THREAD->clr_do_not_unlock();
562
563
// Notify jvmti.
564
// Whenever JVMTI puts a thread in interp_only_mode, method
565
// entry/exit events are sent for that thread to track stack depth.
566
if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {
567
CALL_VM(InterpreterRuntime::post_method_entry(THREAD),
568
handle_exception);
569
}
570
571
goto run;
572
}
573
574
case popping_frame: {
575
// returned from a java call to pop the frame, restart the call
576
// clear the message so we don't confuse ourselves later
577
assert(THREAD->pop_frame_in_process(), "wrong frame pop state");
578
istate->set_msg(no_request);
579
THREAD->clr_pop_frame_in_process();
580
goto run;
581
}
582
583
case method_resume: {
584
if ((istate->_stack_base - istate->_stack_limit) != istate->method()->max_stack() + 1) {
585
// resume
586
os::breakpoint();
587
}
588
// returned from a java call, continue executing.
589
if (THREAD->has_pending_popframe() && !THREAD->pop_frame_in_process()) {
590
goto handle_Pop_Frame;
591
}
592
if (THREAD->jvmti_thread_state() &&
593
THREAD->jvmti_thread_state()->is_earlyret_pending()) {
594
goto handle_Early_Return;
595
}
596
597
if (THREAD->has_pending_exception()) goto handle_exception;
598
// Update the pc by the saved amount of the invoke bytecode size
599
UPDATE_PC(istate->bcp_advance());
600
goto run;
601
}
602
603
case deopt_resume2: {
604
// Returned from an opcode that will reexecute. Deopt was
605
// a result of a PopFrame request.
606
//
607
goto run;
608
}
609
610
case deopt_resume: {
611
// Returned from an opcode that has completed. The stack has
612
// the result all we need to do is skip across the bytecode
613
// and continue (assuming there is no exception pending)
614
//
615
// compute continuation length
616
//
617
// Note: it is possible to deopt at a return_register_finalizer opcode
618
// because this requires entering the vm to do the registering. While the
619
// opcode is complete we can't advance because there are no more opcodes
620
// much like trying to deopt at a poll return. In that has we simply
621
// get out of here
622
//
623
if ( Bytecodes::code_at(METHOD, pc) == Bytecodes::_return_register_finalizer) {
624
// this will do the right thing even if an exception is pending.
625
goto handle_return;
626
}
627
UPDATE_PC(Bytecodes::length_at(METHOD, pc));
628
if (THREAD->has_pending_exception()) goto handle_exception;
629
goto run;
630
}
631
case got_monitors: {
632
// continue locking now that we have a monitor to use
633
// we expect to find newly allocated monitor at the "top" of the monitor stack.
634
oop lockee = STACK_OBJECT(-1);
635
VERIFY_OOP(lockee);
636
// derefing's lockee ought to provoke implicit null check
637
// find a free monitor
638
BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base();
639
assert(entry->obj() == NULL, "Frame manager didn't allocate the monitor");
640
entry->set_obj(lockee);
641
642
assert(!UseBiasedLocking, "Not implemented");
643
644
// traditional lightweight locking
645
markWord displaced = lockee->mark().set_unlocked();
646
entry->lock()->set_displaced_header(displaced);
647
bool call_vm = UseHeavyMonitors;
648
if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
649
// Is it simple recursive case?
650
if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
651
entry->lock()->set_displaced_header(markWord::from_pointer(NULL));
652
} else {
653
CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
654
}
655
}
656
UPDATE_PC_AND_TOS(1, -1);
657
goto run;
658
}
659
default: {
660
fatal("Unexpected message from frame manager");
661
}
662
}
663
664
run:
665
666
DO_UPDATE_INSTRUCTION_COUNT(*pc)
667
DEBUGGER_SINGLE_STEP_NOTIFY();
668
#ifdef PREFETCH_OPCCODE
669
opcode = *pc; /* prefetch first opcode */
670
#endif
671
672
#ifndef USELABELS
673
while (1)
674
#endif
675
{
676
#ifndef PREFETCH_OPCCODE
677
opcode = *pc;
678
#endif
679
// Seems like this happens twice per opcode. At worst this is only
680
// need at entry to the loop.
681
// DEBUGGER_SINGLE_STEP_NOTIFY();
682
/* Using this labels avoids double breakpoints when quickening and
683
* when returing from transition frames.
684
*/
685
opcode_switch:
686
assert(istate == orig, "Corrupted istate");
687
/* QQQ Hmm this has knowledge of direction, ought to be a stack method */
688
assert(topOfStack >= istate->stack_limit(), "Stack overrun");
689
assert(topOfStack < istate->stack_base(), "Stack underrun");
690
691
#ifdef USELABELS
692
DISPATCH(opcode);
693
#else
694
switch (opcode)
695
#endif
696
{
697
CASE(_nop):
698
UPDATE_PC_AND_CONTINUE(1);
699
700
/* Push miscellaneous constants onto the stack. */
701
702
CASE(_aconst_null):
703
SET_STACK_OBJECT(NULL, 0);
704
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
705
706
#undef OPC_CONST_n
707
#define OPC_CONST_n(opcode, const_type, value) \
708
CASE(opcode): \
709
SET_STACK_ ## const_type(value, 0); \
710
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
711
712
OPC_CONST_n(_iconst_m1, INT, -1);
713
OPC_CONST_n(_iconst_0, INT, 0);
714
OPC_CONST_n(_iconst_1, INT, 1);
715
OPC_CONST_n(_iconst_2, INT, 2);
716
OPC_CONST_n(_iconst_3, INT, 3);
717
OPC_CONST_n(_iconst_4, INT, 4);
718
OPC_CONST_n(_iconst_5, INT, 5);
719
OPC_CONST_n(_fconst_0, FLOAT, 0.0);
720
OPC_CONST_n(_fconst_1, FLOAT, 1.0);
721
OPC_CONST_n(_fconst_2, FLOAT, 2.0);
722
723
#undef OPC_CONST2_n
724
#define OPC_CONST2_n(opcname, value, key, kind) \
725
CASE(_##opcname): \
726
{ \
727
SET_STACK_ ## kind(VM##key##Const##value(), 1); \
728
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); \
729
}
730
OPC_CONST2_n(dconst_0, Zero, double, DOUBLE);
731
OPC_CONST2_n(dconst_1, One, double, DOUBLE);
732
OPC_CONST2_n(lconst_0, Zero, long, LONG);
733
OPC_CONST2_n(lconst_1, One, long, LONG);
734
735
/* Load constant from constant pool: */
736
737
/* Push a 1-byte signed integer value onto the stack. */
738
CASE(_bipush):
739
SET_STACK_INT((jbyte)(pc[1]), 0);
740
UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);
741
742
/* Push a 2-byte signed integer constant onto the stack. */
743
CASE(_sipush):
744
SET_STACK_INT((int16_t)Bytes::get_Java_u2(pc + 1), 0);
745
UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
746
747
/* load from local variable */
748
749
CASE(_aload):
750
VERIFY_OOP(LOCALS_OBJECT(pc[1]));
751
SET_STACK_OBJECT(LOCALS_OBJECT(pc[1]), 0);
752
UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);
753
754
CASE(_iload):
755
CASE(_fload):
756
SET_STACK_SLOT(LOCALS_SLOT(pc[1]), 0);
757
UPDATE_PC_AND_TOS_AND_CONTINUE(2, 1);
758
759
CASE(_lload):
760
SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(pc[1]), 1);
761
UPDATE_PC_AND_TOS_AND_CONTINUE(2, 2);
762
763
CASE(_dload):
764
SET_STACK_DOUBLE_FROM_ADDR(LOCALS_DOUBLE_AT(pc[1]), 1);
765
UPDATE_PC_AND_TOS_AND_CONTINUE(2, 2);
766
767
#undef OPC_LOAD_n
768
#define OPC_LOAD_n(num) \
769
CASE(_aload_##num): \
770
VERIFY_OOP(LOCALS_OBJECT(num)); \
771
SET_STACK_OBJECT(LOCALS_OBJECT(num), 0); \
772
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); \
773
\
774
CASE(_iload_##num): \
775
CASE(_fload_##num): \
776
SET_STACK_SLOT(LOCALS_SLOT(num), 0); \
777
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1); \
778
\
779
CASE(_lload_##num): \
780
SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(num), 1); \
781
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2); \
782
CASE(_dload_##num): \
783
SET_STACK_DOUBLE_FROM_ADDR(LOCALS_DOUBLE_AT(num), 1); \
784
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
785
786
OPC_LOAD_n(0);
787
OPC_LOAD_n(1);
788
OPC_LOAD_n(2);
789
OPC_LOAD_n(3);
790
791
/* store to a local variable */
792
793
CASE(_astore):
794
astore(topOfStack, -1, locals, pc[1]);
795
UPDATE_PC_AND_TOS_AND_CONTINUE(2, -1);
796
797
CASE(_istore):
798
CASE(_fstore):
799
SET_LOCALS_SLOT(STACK_SLOT(-1), pc[1]);
800
UPDATE_PC_AND_TOS_AND_CONTINUE(2, -1);
801
802
CASE(_lstore):
803
SET_LOCALS_LONG(STACK_LONG(-1), pc[1]);
804
UPDATE_PC_AND_TOS_AND_CONTINUE(2, -2);
805
806
CASE(_dstore):
807
SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), pc[1]);
808
UPDATE_PC_AND_TOS_AND_CONTINUE(2, -2);
809
810
CASE(_wide): {
811
uint16_t reg = Bytes::get_Java_u2(pc + 2);
812
813
opcode = pc[1];
814
815
// Wide and it's sub-bytecode are counted as separate instructions. If we
816
// don't account for this here, the bytecode trace skips the next bytecode.
817
DO_UPDATE_INSTRUCTION_COUNT(opcode);
818
819
switch(opcode) {
820
case Bytecodes::_aload:
821
VERIFY_OOP(LOCALS_OBJECT(reg));
822
SET_STACK_OBJECT(LOCALS_OBJECT(reg), 0);
823
UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);
824
825
case Bytecodes::_iload:
826
case Bytecodes::_fload:
827
SET_STACK_SLOT(LOCALS_SLOT(reg), 0);
828
UPDATE_PC_AND_TOS_AND_CONTINUE(4, 1);
829
830
case Bytecodes::_lload:
831
SET_STACK_LONG_FROM_ADDR(LOCALS_LONG_AT(reg), 1);
832
UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2);
833
834
case Bytecodes::_dload:
835
SET_STACK_DOUBLE_FROM_ADDR(LOCALS_LONG_AT(reg), 1);
836
UPDATE_PC_AND_TOS_AND_CONTINUE(4, 2);
837
838
case Bytecodes::_astore:
839
astore(topOfStack, -1, locals, reg);
840
UPDATE_PC_AND_TOS_AND_CONTINUE(4, -1);
841
842
case Bytecodes::_istore:
843
case Bytecodes::_fstore:
844
SET_LOCALS_SLOT(STACK_SLOT(-1), reg);
845
UPDATE_PC_AND_TOS_AND_CONTINUE(4, -1);
846
847
case Bytecodes::_lstore:
848
SET_LOCALS_LONG(STACK_LONG(-1), reg);
849
UPDATE_PC_AND_TOS_AND_CONTINUE(4, -2);
850
851
case Bytecodes::_dstore:
852
SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), reg);
853
UPDATE_PC_AND_TOS_AND_CONTINUE(4, -2);
854
855
case Bytecodes::_iinc: {
856
int16_t offset = (int16_t)Bytes::get_Java_u2(pc+4);
857
// Be nice to see what this generates.... QQQ
858
SET_LOCALS_INT(LOCALS_INT(reg) + offset, reg);
859
UPDATE_PC_AND_CONTINUE(6);
860
}
861
case Bytecodes::_ret:
862
pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(reg));
863
UPDATE_PC_AND_CONTINUE(0);
864
default:
865
VM_JAVA_ERROR(vmSymbols::java_lang_InternalError(), "undefined opcode");
866
}
867
}
868
869
870
#undef OPC_STORE_n
871
#define OPC_STORE_n(num) \
872
CASE(_astore_##num): \
873
astore(topOfStack, -1, locals, num); \
874
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \
875
CASE(_istore_##num): \
876
CASE(_fstore_##num): \
877
SET_LOCALS_SLOT(STACK_SLOT(-1), num); \
878
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
879
880
OPC_STORE_n(0);
881
OPC_STORE_n(1);
882
OPC_STORE_n(2);
883
OPC_STORE_n(3);
884
885
#undef OPC_DSTORE_n
886
#define OPC_DSTORE_n(num) \
887
CASE(_dstore_##num): \
888
SET_LOCALS_DOUBLE(STACK_DOUBLE(-1), num); \
889
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \
890
CASE(_lstore_##num): \
891
SET_LOCALS_LONG(STACK_LONG(-1), num); \
892
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);
893
894
OPC_DSTORE_n(0);
895
OPC_DSTORE_n(1);
896
OPC_DSTORE_n(2);
897
OPC_DSTORE_n(3);
898
899
/* stack pop, dup, and insert opcodes */
900
901
902
CASE(_pop): /* Discard the top item on the stack */
903
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
904
905
906
CASE(_pop2): /* Discard the top 2 items on the stack */
907
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2);
908
909
910
CASE(_dup): /* Duplicate the top item on the stack */
911
dup(topOfStack);
912
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
913
914
CASE(_dup2): /* Duplicate the top 2 items on the stack */
915
dup2(topOfStack);
916
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
917
918
CASE(_dup_x1): /* insert top word two down */
919
dup_x1(topOfStack);
920
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
921
922
CASE(_dup_x2): /* insert top word three down */
923
dup_x2(topOfStack);
924
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
925
926
CASE(_dup2_x1): /* insert top 2 slots three down */
927
dup2_x1(topOfStack);
928
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
929
930
CASE(_dup2_x2): /* insert top 2 slots four down */
931
dup2_x2(topOfStack);
932
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
933
934
CASE(_swap): { /* swap top two elements on the stack */
935
swap(topOfStack);
936
UPDATE_PC_AND_CONTINUE(1);
937
}
938
939
/* Perform various binary integer operations */
940
941
#undef OPC_INT_BINARY
942
#define OPC_INT_BINARY(opcname, opname, test) \
943
CASE(_i##opcname): \
944
if (test && (STACK_INT(-1) == 0)) { \
945
VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \
946
"/ by zero"); \
947
} \
948
SET_STACK_INT(VMint##opname(STACK_INT(-2), \
949
STACK_INT(-1)), \
950
-2); \
951
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \
952
CASE(_l##opcname): \
953
{ \
954
if (test) { \
955
jlong l1 = STACK_LONG(-1); \
956
if (VMlongEqz(l1)) { \
957
VM_JAVA_ERROR(vmSymbols::java_lang_ArithmeticException(), \
958
"/ by long zero"); \
959
} \
960
} \
961
/* First long at (-1,-2) next long at (-3,-4) */ \
962
SET_STACK_LONG(VMlong##opname(STACK_LONG(-3), \
963
STACK_LONG(-1)), \
964
-3); \
965
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \
966
}
967
968
OPC_INT_BINARY(add, Add, 0);
969
OPC_INT_BINARY(sub, Sub, 0);
970
OPC_INT_BINARY(mul, Mul, 0);
971
OPC_INT_BINARY(and, And, 0);
972
OPC_INT_BINARY(or, Or, 0);
973
OPC_INT_BINARY(xor, Xor, 0);
974
OPC_INT_BINARY(div, Div, 1);
975
OPC_INT_BINARY(rem, Rem, 1);
976
977
978
/* Perform various binary floating number operations */
979
/* On some machine/platforms/compilers div zero check can be implicit */
980
981
#undef OPC_FLOAT_BINARY
982
#define OPC_FLOAT_BINARY(opcname, opname) \
983
CASE(_d##opcname): { \
984
SET_STACK_DOUBLE(VMdouble##opname(STACK_DOUBLE(-3), \
985
STACK_DOUBLE(-1)), \
986
-3); \
987
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -2); \
988
} \
989
CASE(_f##opcname): \
990
SET_STACK_FLOAT(VMfloat##opname(STACK_FLOAT(-2), \
991
STACK_FLOAT(-1)), \
992
-2); \
993
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
994
995
996
OPC_FLOAT_BINARY(add, Add);
997
OPC_FLOAT_BINARY(sub, Sub);
998
OPC_FLOAT_BINARY(mul, Mul);
999
OPC_FLOAT_BINARY(div, Div);
1000
OPC_FLOAT_BINARY(rem, Rem);
1001
1002
/* Shift operations
1003
* Shift left int and long: ishl, lshl
1004
* Logical shift right int and long w/zero extension: iushr, lushr
1005
* Arithmetic shift right int and long w/sign extension: ishr, lshr
1006
*/
1007
1008
#undef OPC_SHIFT_BINARY
1009
#define OPC_SHIFT_BINARY(opcname, opname) \
1010
CASE(_i##opcname): \
1011
SET_STACK_INT(VMint##opname(STACK_INT(-2), \
1012
STACK_INT(-1)), \
1013
-2); \
1014
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \
1015
CASE(_l##opcname): \
1016
{ \
1017
SET_STACK_LONG(VMlong##opname(STACK_LONG(-2), \
1018
STACK_INT(-1)), \
1019
-2); \
1020
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \
1021
}
1022
1023
OPC_SHIFT_BINARY(shl, Shl);
1024
OPC_SHIFT_BINARY(shr, Shr);
1025
OPC_SHIFT_BINARY(ushr, Ushr);
1026
1027
/* Increment local variable by constant */
1028
CASE(_iinc):
1029
{
1030
// locals[pc[1]].j.i += (jbyte)(pc[2]);
1031
SET_LOCALS_INT(LOCALS_INT(pc[1]) + (jbyte)(pc[2]), pc[1]);
1032
UPDATE_PC_AND_CONTINUE(3);
1033
}
1034
1035
/* negate the value on the top of the stack */
1036
1037
CASE(_ineg):
1038
SET_STACK_INT(VMintNeg(STACK_INT(-1)), -1);
1039
UPDATE_PC_AND_CONTINUE(1);
1040
1041
CASE(_fneg):
1042
SET_STACK_FLOAT(VMfloatNeg(STACK_FLOAT(-1)), -1);
1043
UPDATE_PC_AND_CONTINUE(1);
1044
1045
CASE(_lneg):
1046
{
1047
SET_STACK_LONG(VMlongNeg(STACK_LONG(-1)), -1);
1048
UPDATE_PC_AND_CONTINUE(1);
1049
}
1050
1051
CASE(_dneg):
1052
{
1053
SET_STACK_DOUBLE(VMdoubleNeg(STACK_DOUBLE(-1)), -1);
1054
UPDATE_PC_AND_CONTINUE(1);
1055
}
1056
1057
/* Conversion operations */
1058
1059
CASE(_i2f): /* convert top of stack int to float */
1060
SET_STACK_FLOAT(VMint2Float(STACK_INT(-1)), -1);
1061
UPDATE_PC_AND_CONTINUE(1);
1062
1063
CASE(_i2l): /* convert top of stack int to long */
1064
{
1065
// this is ugly QQQ
1066
jlong r = VMint2Long(STACK_INT(-1));
1067
MORE_STACK(-1); // Pop
1068
SET_STACK_LONG(r, 1);
1069
1070
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1071
}
1072
1073
CASE(_i2d): /* convert top of stack int to double */
1074
{
1075
// this is ugly QQQ (why cast to jlong?? )
1076
jdouble r = (jlong)STACK_INT(-1);
1077
MORE_STACK(-1); // Pop
1078
SET_STACK_DOUBLE(r, 1);
1079
1080
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1081
}
1082
1083
CASE(_l2i): /* convert top of stack long to int */
1084
{
1085
jint r = VMlong2Int(STACK_LONG(-1));
1086
MORE_STACK(-2); // Pop
1087
SET_STACK_INT(r, 0);
1088
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1089
}
1090
1091
CASE(_l2f): /* convert top of stack long to float */
1092
{
1093
jlong r = STACK_LONG(-1);
1094
MORE_STACK(-2); // Pop
1095
SET_STACK_FLOAT(VMlong2Float(r), 0);
1096
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1097
}
1098
1099
CASE(_l2d): /* convert top of stack long to double */
1100
{
1101
jlong r = STACK_LONG(-1);
1102
MORE_STACK(-2); // Pop
1103
SET_STACK_DOUBLE(VMlong2Double(r), 1);
1104
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1105
}
1106
1107
CASE(_f2i): /* Convert top of stack float to int */
1108
SET_STACK_INT(SharedRuntime::f2i(STACK_FLOAT(-1)), -1);
1109
UPDATE_PC_AND_CONTINUE(1);
1110
1111
CASE(_f2l): /* convert top of stack float to long */
1112
{
1113
jlong r = SharedRuntime::f2l(STACK_FLOAT(-1));
1114
MORE_STACK(-1); // POP
1115
SET_STACK_LONG(r, 1);
1116
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1117
}
1118
1119
CASE(_f2d): /* convert top of stack float to double */
1120
{
1121
jfloat f;
1122
jdouble r;
1123
f = STACK_FLOAT(-1);
1124
r = (jdouble) f;
1125
MORE_STACK(-1); // POP
1126
SET_STACK_DOUBLE(r, 1);
1127
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1128
}
1129
1130
CASE(_d2i): /* convert top of stack double to int */
1131
{
1132
jint r1 = SharedRuntime::d2i(STACK_DOUBLE(-1));
1133
MORE_STACK(-2);
1134
SET_STACK_INT(r1, 0);
1135
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1136
}
1137
1138
CASE(_d2f): /* convert top of stack double to float */
1139
{
1140
jfloat r1 = VMdouble2Float(STACK_DOUBLE(-1));
1141
MORE_STACK(-2);
1142
SET_STACK_FLOAT(r1, 0);
1143
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1144
}
1145
1146
CASE(_d2l): /* convert top of stack double to long */
1147
{
1148
jlong r1 = SharedRuntime::d2l(STACK_DOUBLE(-1));
1149
MORE_STACK(-2);
1150
SET_STACK_LONG(r1, 1);
1151
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 2);
1152
}
1153
1154
CASE(_i2b):
1155
SET_STACK_INT(VMint2Byte(STACK_INT(-1)), -1);
1156
UPDATE_PC_AND_CONTINUE(1);
1157
1158
CASE(_i2c):
1159
SET_STACK_INT(VMint2Char(STACK_INT(-1)), -1);
1160
UPDATE_PC_AND_CONTINUE(1);
1161
1162
CASE(_i2s):
1163
SET_STACK_INT(VMint2Short(STACK_INT(-1)), -1);
1164
UPDATE_PC_AND_CONTINUE(1);
1165
1166
/* comparison operators */
1167
1168
1169
#define COMPARISON_OP(name, comparison) \
1170
CASE(_if_icmp##name): { \
1171
int skip = (STACK_INT(-2) comparison STACK_INT(-1)) \
1172
? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
1173
address branch_pc = pc; \
1174
UPDATE_PC_AND_TOS(skip, -2); \
1175
DO_BACKEDGE_CHECKS(skip, branch_pc); \
1176
CONTINUE; \
1177
} \
1178
CASE(_if##name): { \
1179
int skip = (STACK_INT(-1) comparison 0) \
1180
? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
1181
address branch_pc = pc; \
1182
UPDATE_PC_AND_TOS(skip, -1); \
1183
DO_BACKEDGE_CHECKS(skip, branch_pc); \
1184
CONTINUE; \
1185
}
1186
1187
#define COMPARISON_OP2(name, comparison) \
1188
COMPARISON_OP(name, comparison) \
1189
CASE(_if_acmp##name): { \
1190
int skip = (STACK_OBJECT(-2) comparison STACK_OBJECT(-1)) \
1191
? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
1192
address branch_pc = pc; \
1193
UPDATE_PC_AND_TOS(skip, -2); \
1194
DO_BACKEDGE_CHECKS(skip, branch_pc); \
1195
CONTINUE; \
1196
}
1197
1198
#define NULL_COMPARISON_NOT_OP(name) \
1199
CASE(_if##name): { \
1200
int skip = (!(STACK_OBJECT(-1) == NULL)) \
1201
? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
1202
address branch_pc = pc; \
1203
UPDATE_PC_AND_TOS(skip, -1); \
1204
DO_BACKEDGE_CHECKS(skip, branch_pc); \
1205
CONTINUE; \
1206
}
1207
1208
#define NULL_COMPARISON_OP(name) \
1209
CASE(_if##name): { \
1210
int skip = ((STACK_OBJECT(-1) == NULL)) \
1211
? (int16_t)Bytes::get_Java_u2(pc + 1) : 3; \
1212
address branch_pc = pc; \
1213
UPDATE_PC_AND_TOS(skip, -1); \
1214
DO_BACKEDGE_CHECKS(skip, branch_pc); \
1215
CONTINUE; \
1216
}
1217
COMPARISON_OP(lt, <);
1218
COMPARISON_OP(gt, >);
1219
COMPARISON_OP(le, <=);
1220
COMPARISON_OP(ge, >=);
1221
COMPARISON_OP2(eq, ==); /* include ref comparison */
1222
COMPARISON_OP2(ne, !=); /* include ref comparison */
1223
NULL_COMPARISON_OP(null);
1224
NULL_COMPARISON_NOT_OP(nonnull);
1225
1226
/* Goto pc at specified offset in switch table. */
1227
1228
CASE(_tableswitch): {
1229
jint* lpc = (jint*)VMalignWordUp(pc+1);
1230
int32_t key = STACK_INT(-1);
1231
int32_t low = Bytes::get_Java_u4((address)&lpc[1]);
1232
int32_t high = Bytes::get_Java_u4((address)&lpc[2]);
1233
int32_t skip;
1234
key -= low;
1235
if (((uint32_t) key > (uint32_t)(high - low))) {
1236
skip = Bytes::get_Java_u4((address)&lpc[0]);
1237
} else {
1238
skip = Bytes::get_Java_u4((address)&lpc[key + 3]);
1239
}
1240
// Does this really need a full backedge check (osr)?
1241
address branch_pc = pc;
1242
UPDATE_PC_AND_TOS(skip, -1);
1243
DO_BACKEDGE_CHECKS(skip, branch_pc);
1244
CONTINUE;
1245
}
1246
1247
/* Goto pc whose table entry matches specified key. */
1248
1249
CASE(_lookupswitch): {
1250
jint* lpc = (jint*)VMalignWordUp(pc+1);
1251
int32_t key = STACK_INT(-1);
1252
int32_t skip = Bytes::get_Java_u4((address) lpc); /* default amount */
1253
int32_t npairs = Bytes::get_Java_u4((address) &lpc[1]);
1254
while (--npairs >= 0) {
1255
lpc += 2;
1256
if (key == (int32_t)Bytes::get_Java_u4((address)lpc)) {
1257
skip = Bytes::get_Java_u4((address)&lpc[1]);
1258
break;
1259
}
1260
}
1261
address branch_pc = pc;
1262
UPDATE_PC_AND_TOS(skip, -1);
1263
DO_BACKEDGE_CHECKS(skip, branch_pc);
1264
CONTINUE;
1265
}
1266
1267
CASE(_fcmpl):
1268
CASE(_fcmpg):
1269
{
1270
SET_STACK_INT(VMfloatCompare(STACK_FLOAT(-2),
1271
STACK_FLOAT(-1),
1272
(opcode == Bytecodes::_fcmpl ? -1 : 1)),
1273
-2);
1274
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1275
}
1276
1277
CASE(_dcmpl):
1278
CASE(_dcmpg):
1279
{
1280
int r = VMdoubleCompare(STACK_DOUBLE(-3),
1281
STACK_DOUBLE(-1),
1282
(opcode == Bytecodes::_dcmpl ? -1 : 1));
1283
MORE_STACK(-4); // Pop
1284
SET_STACK_INT(r, 0);
1285
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1286
}
1287
1288
CASE(_lcmp):
1289
{
1290
int r = VMlongCompare(STACK_LONG(-3), STACK_LONG(-1));
1291
MORE_STACK(-4);
1292
SET_STACK_INT(r, 0);
1293
UPDATE_PC_AND_TOS_AND_CONTINUE(1, 1);
1294
}
1295
1296
1297
/* Return from a method */
1298
1299
CASE(_areturn):
1300
CASE(_ireturn):
1301
CASE(_freturn):
1302
CASE(_lreturn):
1303
CASE(_dreturn):
1304
CASE(_return): {
1305
// Allow a safepoint before returning to frame manager.
1306
RETURN_SAFEPOINT;
1307
goto handle_return;
1308
}
1309
1310
CASE(_return_register_finalizer): {
1311
oop rcvr = LOCALS_OBJECT(0);
1312
VERIFY_OOP(rcvr);
1313
if (rcvr->klass()->has_finalizer()) {
1314
CALL_VM(InterpreterRuntime::register_finalizer(THREAD, rcvr), handle_exception);
1315
}
1316
goto handle_return;
1317
}
1318
1319
/* Array access byte-codes */
1320
1321
/* Every array access byte-code starts out like this */
1322
// arrayOopDesc* arrObj = (arrayOopDesc*)STACK_OBJECT(arrayOff);
1323
#define ARRAY_INTRO(arrayOff) \
1324
arrayOop arrObj = (arrayOop)STACK_OBJECT(arrayOff); \
1325
jint index = STACK_INT(arrayOff + 1); \
1326
/* Two integers, the additional message, and the null-terminator */ \
1327
char message[2 * jintAsStringSize + 33]; \
1328
CHECK_NULL(arrObj); \
1329
if ((uint32_t)index >= (uint32_t)arrObj->length()) { \
1330
jio_snprintf(message, sizeof(message), \
1331
"Index %d out of bounds for length %d", \
1332
index, arrObj->length()); \
1333
VM_JAVA_ERROR(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), \
1334
message); \
1335
}
1336
1337
/* 32-bit loads. These handle conversion from < 32-bit types */
1338
#define ARRAY_LOADTO32(T, T2, format, stackRes, extra) \
1339
{ \
1340
ARRAY_INTRO(-2); \
1341
(void)extra; \
1342
SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), \
1343
-2); \
1344
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1); \
1345
}
1346
1347
/* 64-bit loads */
1348
#define ARRAY_LOADTO64(T,T2, stackRes, extra) \
1349
{ \
1350
ARRAY_INTRO(-2); \
1351
SET_ ## stackRes(*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)), -1); \
1352
(void)extra; \
1353
UPDATE_PC_AND_CONTINUE(1); \
1354
}
1355
1356
CASE(_iaload):
1357
ARRAY_LOADTO32(T_INT, jint, "%d", STACK_INT, 0);
1358
CASE(_faload):
1359
ARRAY_LOADTO32(T_FLOAT, jfloat, "%f", STACK_FLOAT, 0);
1360
CASE(_aaload): {
1361
ARRAY_INTRO(-2);
1362
SET_STACK_OBJECT(((objArrayOop) arrObj)->obj_at(index), -2);
1363
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1364
}
1365
CASE(_baload):
1366
ARRAY_LOADTO32(T_BYTE, jbyte, "%d", STACK_INT, 0);
1367
CASE(_caload):
1368
ARRAY_LOADTO32(T_CHAR, jchar, "%d", STACK_INT, 0);
1369
CASE(_saload):
1370
ARRAY_LOADTO32(T_SHORT, jshort, "%d", STACK_INT, 0);
1371
CASE(_laload):
1372
ARRAY_LOADTO64(T_LONG, jlong, STACK_LONG, 0);
1373
CASE(_daload):
1374
ARRAY_LOADTO64(T_DOUBLE, jdouble, STACK_DOUBLE, 0);
1375
1376
/* 32-bit stores. These handle conversion to < 32-bit types */
1377
#define ARRAY_STOREFROM32(T, T2, format, stackSrc, extra) \
1378
{ \
1379
ARRAY_INTRO(-3); \
1380
(void)extra; \
1381
*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \
1382
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3); \
1383
}
1384
1385
/* 64-bit stores */
1386
#define ARRAY_STOREFROM64(T, T2, stackSrc, extra) \
1387
{ \
1388
ARRAY_INTRO(-4); \
1389
(void)extra; \
1390
*(T2 *)(((address) arrObj->base(T)) + index * sizeof(T2)) = stackSrc( -1); \
1391
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -4); \
1392
}
1393
1394
CASE(_iastore):
1395
ARRAY_STOREFROM32(T_INT, jint, "%d", STACK_INT, 0);
1396
CASE(_fastore):
1397
ARRAY_STOREFROM32(T_FLOAT, jfloat, "%f", STACK_FLOAT, 0);
1398
/*
1399
* This one looks different because of the assignability check
1400
*/
1401
CASE(_aastore): {
1402
oop rhsObject = STACK_OBJECT(-1);
1403
VERIFY_OOP(rhsObject);
1404
ARRAY_INTRO( -3);
1405
// arrObj, index are set
1406
if (rhsObject != NULL) {
1407
/* Check assignability of rhsObject into arrObj */
1408
Klass* rhsKlass = rhsObject->klass(); // EBX (subclass)
1409
Klass* elemKlass = ObjArrayKlass::cast(arrObj->klass())->element_klass(); // superklass EAX
1410
//
1411
// Check for compatibilty. This check must not GC!!
1412
// Seems way more expensive now that we must dispatch
1413
//
1414
if (rhsKlass != elemKlass && !rhsKlass->is_subtype_of(elemKlass)) { // ebx->is...
1415
VM_JAVA_ERROR(vmSymbols::java_lang_ArrayStoreException(), "");
1416
}
1417
}
1418
((objArrayOop) arrObj)->obj_at_put(index, rhsObject);
1419
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3);
1420
}
1421
CASE(_bastore): {
1422
ARRAY_INTRO(-3);
1423
int item = STACK_INT(-1);
1424
// if it is a T_BOOLEAN array, mask the stored value to 0/1
1425
if (arrObj->klass() == Universe::boolArrayKlassObj()) {
1426
item &= 1;
1427
} else {
1428
assert(arrObj->klass() == Universe::byteArrayKlassObj(),
1429
"should be byte array otherwise");
1430
}
1431
((typeArrayOop)arrObj)->byte_at_put(index, item);
1432
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -3);
1433
}
1434
CASE(_castore):
1435
ARRAY_STOREFROM32(T_CHAR, jchar, "%d", STACK_INT, 0);
1436
CASE(_sastore):
1437
ARRAY_STOREFROM32(T_SHORT, jshort, "%d", STACK_INT, 0);
1438
CASE(_lastore):
1439
ARRAY_STOREFROM64(T_LONG, jlong, STACK_LONG, 0);
1440
CASE(_dastore):
1441
ARRAY_STOREFROM64(T_DOUBLE, jdouble, STACK_DOUBLE, 0);
1442
1443
CASE(_arraylength):
1444
{
1445
arrayOop ary = (arrayOop) STACK_OBJECT(-1);
1446
CHECK_NULL(ary);
1447
SET_STACK_INT(ary->length(), -1);
1448
UPDATE_PC_AND_CONTINUE(1);
1449
}
1450
1451
/* monitorenter and monitorexit for locking/unlocking an object */
1452
1453
CASE(_monitorenter): {
1454
oop lockee = STACK_OBJECT(-1);
1455
// derefing's lockee ought to provoke implicit null check
1456
CHECK_NULL(lockee);
1457
// find a free monitor or one already allocated for this object
1458
// if we find a matching object then we need a new monitor
1459
// since this is recursive enter
1460
BasicObjectLock* limit = istate->monitor_base();
1461
BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1462
BasicObjectLock* entry = NULL;
1463
while (most_recent != limit ) {
1464
if (most_recent->obj() == NULL) entry = most_recent;
1465
else if (most_recent->obj() == lockee) break;
1466
most_recent++;
1467
}
1468
if (entry != NULL) {
1469
entry->set_obj(lockee);
1470
1471
assert(!UseBiasedLocking, "Not implemented");
1472
1473
// traditional lightweight locking
1474
markWord displaced = lockee->mark().set_unlocked();
1475
entry->lock()->set_displaced_header(displaced);
1476
bool call_vm = UseHeavyMonitors;
1477
if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
1478
// Is it simple recursive case?
1479
if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
1480
entry->lock()->set_displaced_header(markWord::from_pointer(NULL));
1481
} else {
1482
CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1483
}
1484
}
1485
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1486
} else {
1487
istate->set_msg(more_monitors);
1488
UPDATE_PC_AND_RETURN(0); // Re-execute
1489
}
1490
}
1491
1492
CASE(_monitorexit): {
1493
oop lockee = STACK_OBJECT(-1);
1494
CHECK_NULL(lockee);
1495
// derefing's lockee ought to provoke implicit null check
1496
// find our monitor slot
1497
BasicObjectLock* limit = istate->monitor_base();
1498
BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1499
while (most_recent != limit ) {
1500
if ((most_recent)->obj() == lockee) {
1501
BasicLock* lock = most_recent->lock();
1502
markWord header = lock->displaced_header();
1503
most_recent->set_obj(NULL);
1504
1505
assert(!UseBiasedLocking, "Not implemented");
1506
1507
// If it isn't recursive we either must swap old header or call the runtime
1508
bool call_vm = UseHeavyMonitors;
1509
if (header.to_pointer() != NULL || call_vm) {
1510
markWord old_header = markWord::encode(lock);
1511
if (call_vm || lockee->cas_set_mark(header, old_header) != old_header) {
1512
// restore object for the slow case
1513
most_recent->set_obj(lockee);
1514
InterpreterRuntime::monitorexit(most_recent);
1515
}
1516
}
1517
UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1518
}
1519
most_recent++;
1520
}
1521
// Need to throw illegal monitor state exception
1522
CALL_VM(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD), handle_exception);
1523
ShouldNotReachHere();
1524
}
1525
1526
/* All of the non-quick opcodes. */
1527
1528
/* -Set clobbersCpIndex true if the quickened opcode clobbers the
1529
* constant pool index in the instruction.
1530
*/
1531
CASE(_getfield):
1532
CASE(_getstatic):
1533
{
1534
u2 index;
1535
ConstantPoolCacheEntry* cache;
1536
index = Bytes::get_native_u2(pc+1);
1537
1538
// QQQ Need to make this as inlined as possible. Probably need to
1539
// split all the bytecode cases out so c++ compiler has a chance
1540
// for constant prop to fold everything possible away.
1541
1542
cache = cp->entry_at(index);
1543
if (!cache->is_resolved((Bytecodes::Code)opcode)) {
1544
CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),
1545
handle_exception);
1546
cache = cp->entry_at(index);
1547
}
1548
1549
if (JVMTI_ENABLED) {
1550
int *count_addr;
1551
oop obj;
1552
// Check to see if a field modification watch has been set
1553
// before we take the time to call into the VM.
1554
count_addr = (int *)JvmtiExport::get_field_access_count_addr();
1555
if ( *count_addr > 0 ) {
1556
if ((Bytecodes::Code)opcode == Bytecodes::_getstatic) {
1557
obj = NULL;
1558
} else {
1559
obj = STACK_OBJECT(-1);
1560
VERIFY_OOP(obj);
1561
}
1562
CALL_VM(InterpreterRuntime::post_field_access(THREAD,
1563
obj,
1564
cache),
1565
handle_exception);
1566
}
1567
}
1568
1569
oop obj;
1570
if ((Bytecodes::Code)opcode == Bytecodes::_getstatic) {
1571
Klass* k = cache->f1_as_klass();
1572
obj = k->java_mirror();
1573
MORE_STACK(1); // Assume single slot push
1574
} else {
1575
obj = STACK_OBJECT(-1);
1576
CHECK_NULL(obj);
1577
}
1578
1579
//
1580
// Now store the result on the stack
1581
//
1582
TosState tos_type = cache->flag_state();
1583
int field_offset = cache->f2_as_index();
1584
if (cache->is_volatile()) {
1585
if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
1586
OrderAccess::fence();
1587
}
1588
switch (tos_type) {
1589
case btos:
1590
case ztos:
1591
SET_STACK_INT(obj->byte_field_acquire(field_offset), -1);
1592
break;
1593
case ctos:
1594
SET_STACK_INT(obj->char_field_acquire(field_offset), -1);
1595
break;
1596
case stos:
1597
SET_STACK_INT(obj->short_field_acquire(field_offset), -1);
1598
break;
1599
case itos:
1600
SET_STACK_INT(obj->int_field_acquire(field_offset), -1);
1601
break;
1602
case ftos:
1603
SET_STACK_FLOAT(obj->float_field_acquire(field_offset), -1);
1604
break;
1605
case ltos:
1606
SET_STACK_LONG(obj->long_field_acquire(field_offset), 0);
1607
MORE_STACK(1);
1608
break;
1609
case dtos:
1610
SET_STACK_DOUBLE(obj->double_field_acquire(field_offset), 0);
1611
MORE_STACK(1);
1612
break;
1613
case atos: {
1614
oop val = obj->obj_field_acquire(field_offset);
1615
VERIFY_OOP(val);
1616
SET_STACK_OBJECT(val, -1);
1617
break;
1618
}
1619
default:
1620
ShouldNotReachHere();
1621
}
1622
} else {
1623
switch (tos_type) {
1624
case btos:
1625
case ztos:
1626
SET_STACK_INT(obj->byte_field(field_offset), -1);
1627
break;
1628
case ctos:
1629
SET_STACK_INT(obj->char_field(field_offset), -1);
1630
break;
1631
case stos:
1632
SET_STACK_INT(obj->short_field(field_offset), -1);
1633
break;
1634
case itos:
1635
SET_STACK_INT(obj->int_field(field_offset), -1);
1636
break;
1637
case ftos:
1638
SET_STACK_FLOAT(obj->float_field(field_offset), -1);
1639
break;
1640
case ltos:
1641
SET_STACK_LONG(obj->long_field(field_offset), 0);
1642
MORE_STACK(1);
1643
break;
1644
case dtos:
1645
SET_STACK_DOUBLE(obj->double_field(field_offset), 0);
1646
MORE_STACK(1);
1647
break;
1648
case atos: {
1649
oop val = obj->obj_field(field_offset);
1650
VERIFY_OOP(val);
1651
SET_STACK_OBJECT(val, -1);
1652
break;
1653
}
1654
default:
1655
ShouldNotReachHere();
1656
}
1657
}
1658
1659
UPDATE_PC_AND_CONTINUE(3);
1660
}
1661
1662
CASE(_putfield):
1663
CASE(_putstatic):
1664
{
1665
u2 index = Bytes::get_native_u2(pc+1);
1666
ConstantPoolCacheEntry* cache = cp->entry_at(index);
1667
if (!cache->is_resolved((Bytecodes::Code)opcode)) {
1668
CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),
1669
handle_exception);
1670
cache = cp->entry_at(index);
1671
}
1672
1673
if (JVMTI_ENABLED) {
1674
int *count_addr;
1675
oop obj;
1676
// Check to see if a field modification watch has been set
1677
// before we take the time to call into the VM.
1678
count_addr = (int *)JvmtiExport::get_field_modification_count_addr();
1679
if ( *count_addr > 0 ) {
1680
if ((Bytecodes::Code)opcode == Bytecodes::_putstatic) {
1681
obj = NULL;
1682
}
1683
else {
1684
if (cache->is_long() || cache->is_double()) {
1685
obj = STACK_OBJECT(-3);
1686
} else {
1687
obj = STACK_OBJECT(-2);
1688
}
1689
VERIFY_OOP(obj);
1690
}
1691
1692
CALL_VM(InterpreterRuntime::post_field_modification(THREAD,
1693
obj,
1694
cache,
1695
(jvalue *)STACK_SLOT(-1)),
1696
handle_exception);
1697
}
1698
}
1699
1700
// QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases
1701
// out so c++ compiler has a chance for constant prop to fold everything possible away.
1702
1703
oop obj;
1704
int count;
1705
TosState tos_type = cache->flag_state();
1706
1707
count = -1;
1708
if (tos_type == ltos || tos_type == dtos) {
1709
--count;
1710
}
1711
if ((Bytecodes::Code)opcode == Bytecodes::_putstatic) {
1712
Klass* k = cache->f1_as_klass();
1713
obj = k->java_mirror();
1714
} else {
1715
--count;
1716
obj = STACK_OBJECT(count);
1717
CHECK_NULL(obj);
1718
}
1719
1720
//
1721
// Now store the result
1722
//
1723
int field_offset = cache->f2_as_index();
1724
if (cache->is_volatile()) {
1725
switch (tos_type) {
1726
case ztos:
1727
obj->release_byte_field_put(field_offset, (STACK_INT(-1) & 1)); // only store LSB
1728
break;
1729
case btos:
1730
obj->release_byte_field_put(field_offset, STACK_INT(-1));
1731
break;
1732
case ctos:
1733
obj->release_char_field_put(field_offset, STACK_INT(-1));
1734
break;
1735
case stos:
1736
obj->release_short_field_put(field_offset, STACK_INT(-1));
1737
break;
1738
case itos:
1739
obj->release_int_field_put(field_offset, STACK_INT(-1));
1740
break;
1741
case ftos:
1742
obj->release_float_field_put(field_offset, STACK_FLOAT(-1));
1743
break;
1744
case ltos:
1745
obj->release_long_field_put(field_offset, STACK_LONG(-1));
1746
break;
1747
case dtos:
1748
obj->release_double_field_put(field_offset, STACK_DOUBLE(-1));
1749
break;
1750
case atos: {
1751
oop val = STACK_OBJECT(-1);
1752
VERIFY_OOP(val);
1753
obj->release_obj_field_put(field_offset, val);
1754
break;
1755
}
1756
default:
1757
ShouldNotReachHere();
1758
}
1759
OrderAccess::storeload();
1760
} else {
1761
switch (tos_type) {
1762
case ztos:
1763
obj->byte_field_put(field_offset, (STACK_INT(-1) & 1)); // only store LSB
1764
break;
1765
case btos:
1766
obj->byte_field_put(field_offset, STACK_INT(-1));
1767
break;
1768
case ctos:
1769
obj->char_field_put(field_offset, STACK_INT(-1));
1770
break;
1771
case stos:
1772
obj->short_field_put(field_offset, STACK_INT(-1));
1773
break;
1774
case itos:
1775
obj->int_field_put(field_offset, STACK_INT(-1));
1776
break;
1777
case ftos:
1778
obj->float_field_put(field_offset, STACK_FLOAT(-1));
1779
break;
1780
case ltos:
1781
obj->long_field_put(field_offset, STACK_LONG(-1));
1782
break;
1783
case dtos:
1784
obj->double_field_put(field_offset, STACK_DOUBLE(-1));
1785
break;
1786
case atos: {
1787
oop val = STACK_OBJECT(-1);
1788
VERIFY_OOP(val);
1789
obj->obj_field_put(field_offset, val);
1790
break;
1791
}
1792
default:
1793
ShouldNotReachHere();
1794
}
1795
}
1796
1797
UPDATE_PC_AND_TOS_AND_CONTINUE(3, count);
1798
}
1799
1800
CASE(_new): {
1801
u2 index = Bytes::get_Java_u2(pc+1);
1802
1803
// Attempt TLAB allocation first.
1804
//
1805
// To do this, we need to make sure:
1806
// - klass is initialized
1807
// - klass can be fastpath allocated (e.g. does not have finalizer)
1808
// - TLAB accepts the allocation
1809
ConstantPool* constants = istate->method()->constants();
1810
if (UseTLAB && !constants->tag_at(index).is_unresolved_klass()) {
1811
Klass* entry = constants->resolved_klass_at(index);
1812
InstanceKlass* ik = InstanceKlass::cast(entry);
1813
if (ik->is_initialized() && ik->can_be_fastpath_allocated()) {
1814
size_t obj_size = ik->size_helper();
1815
HeapWord* result = THREAD->tlab().allocate(obj_size);
1816
if (result != NULL) {
1817
// Initialize object field block:
1818
// - if TLAB is pre-zeroed, we can skip this path
1819
// - in debug mode, ThreadLocalAllocBuffer::allocate mangles
1820
// this area, and we still need to initialize it
1821
if (DEBUG_ONLY(true ||) !ZeroTLAB) {
1822
size_t hdr_size = oopDesc::header_size();
1823
Copy::fill_to_words(result + hdr_size, obj_size - hdr_size, 0);
1824
}
1825
1826
oop obj = cast_to_oop(result);
1827
1828
// Initialize header
1829
assert(!UseBiasedLocking, "Not implemented");
1830
obj->set_mark(markWord::prototype());
1831
obj->set_klass_gap(0);
1832
obj->set_klass(ik);
1833
1834
// Must prevent reordering of stores for object initialization
1835
// with stores that publish the new object.
1836
OrderAccess::storestore();
1837
SET_STACK_OBJECT(obj, 0);
1838
UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
1839
}
1840
}
1841
}
1842
// Slow case allocation
1843
CALL_VM(InterpreterRuntime::_new(THREAD, METHOD->constants(), index),
1844
handle_exception);
1845
// Must prevent reordering of stores for object initialization
1846
// with stores that publish the new object.
1847
OrderAccess::storestore();
1848
SET_STACK_OBJECT(THREAD->vm_result(), 0);
1849
THREAD->set_vm_result(NULL);
1850
UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
1851
}
1852
CASE(_anewarray): {
1853
u2 index = Bytes::get_Java_u2(pc+1);
1854
jint size = STACK_INT(-1);
1855
CALL_VM(InterpreterRuntime::anewarray(THREAD, METHOD->constants(), index, size),
1856
handle_exception);
1857
// Must prevent reordering of stores for object initialization
1858
// with stores that publish the new object.
1859
OrderAccess::storestore();
1860
SET_STACK_OBJECT(THREAD->vm_result(), -1);
1861
THREAD->set_vm_result(NULL);
1862
UPDATE_PC_AND_CONTINUE(3);
1863
}
1864
CASE(_multianewarray): {
1865
jint dims = *(pc+3);
1866
jint size = STACK_INT(-1);
1867
// stack grows down, dimensions are up!
1868
jint *dimarray =
1869
(jint*)&topOfStack[dims * Interpreter::stackElementWords+
1870
Interpreter::stackElementWords-1];
1871
//adjust pointer to start of stack element
1872
CALL_VM(InterpreterRuntime::multianewarray(THREAD, dimarray),
1873
handle_exception);
1874
// Must prevent reordering of stores for object initialization
1875
// with stores that publish the new object.
1876
OrderAccess::storestore();
1877
SET_STACK_OBJECT(THREAD->vm_result(), -dims);
1878
THREAD->set_vm_result(NULL);
1879
UPDATE_PC_AND_TOS_AND_CONTINUE(4, -(dims-1));
1880
}
1881
CASE(_checkcast):
1882
if (STACK_OBJECT(-1) != NULL) {
1883
VERIFY_OOP(STACK_OBJECT(-1));
1884
u2 index = Bytes::get_Java_u2(pc+1);
1885
// Constant pool may have actual klass or unresolved klass. If it is
1886
// unresolved we must resolve it.
1887
if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {
1888
CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);
1889
}
1890
Klass* klassOf = (Klass*) METHOD->constants()->resolved_klass_at(index);
1891
Klass* objKlass = STACK_OBJECT(-1)->klass(); // ebx
1892
//
1893
// Check for compatibilty. This check must not GC!!
1894
// Seems way more expensive now that we must dispatch.
1895
//
1896
if (objKlass != klassOf && !objKlass->is_subtype_of(klassOf)) {
1897
ResourceMark rm(THREAD);
1898
char* message = SharedRuntime::generate_class_cast_message(
1899
objKlass, klassOf);
1900
VM_JAVA_ERROR(vmSymbols::java_lang_ClassCastException(), message);
1901
}
1902
}
1903
UPDATE_PC_AND_CONTINUE(3);
1904
1905
CASE(_instanceof):
1906
if (STACK_OBJECT(-1) == NULL) {
1907
SET_STACK_INT(0, -1);
1908
} else {
1909
VERIFY_OOP(STACK_OBJECT(-1));
1910
u2 index = Bytes::get_Java_u2(pc+1);
1911
// Constant pool may have actual klass or unresolved klass. If it is
1912
// unresolved we must resolve it.
1913
if (METHOD->constants()->tag_at(index).is_unresolved_klass()) {
1914
CALL_VM(InterpreterRuntime::quicken_io_cc(THREAD), handle_exception);
1915
}
1916
Klass* klassOf = (Klass*) METHOD->constants()->resolved_klass_at(index);
1917
Klass* objKlass = STACK_OBJECT(-1)->klass();
1918
//
1919
// Check for compatibilty. This check must not GC!!
1920
// Seems way more expensive now that we must dispatch.
1921
//
1922
if ( objKlass == klassOf || objKlass->is_subtype_of(klassOf)) {
1923
SET_STACK_INT(1, -1);
1924
} else {
1925
SET_STACK_INT(0, -1);
1926
}
1927
}
1928
UPDATE_PC_AND_CONTINUE(3);
1929
1930
CASE(_ldc_w):
1931
CASE(_ldc):
1932
{
1933
u2 index;
1934
bool wide = false;
1935
int incr = 2; // frequent case
1936
if (opcode == Bytecodes::_ldc) {
1937
index = pc[1];
1938
} else {
1939
index = Bytes::get_Java_u2(pc+1);
1940
incr = 3;
1941
wide = true;
1942
}
1943
1944
ConstantPool* constants = METHOD->constants();
1945
switch (constants->tag_at(index).value()) {
1946
case JVM_CONSTANT_Integer:
1947
SET_STACK_INT(constants->int_at(index), 0);
1948
break;
1949
1950
case JVM_CONSTANT_Float:
1951
SET_STACK_FLOAT(constants->float_at(index), 0);
1952
break;
1953
1954
case JVM_CONSTANT_String:
1955
{
1956
oop result = constants->resolved_references()->obj_at(index);
1957
if (result == NULL) {
1958
CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);
1959
SET_STACK_OBJECT(THREAD->vm_result(), 0);
1960
THREAD->set_vm_result(NULL);
1961
} else {
1962
VERIFY_OOP(result);
1963
SET_STACK_OBJECT(result, 0);
1964
}
1965
break;
1966
}
1967
1968
case JVM_CONSTANT_Class:
1969
VERIFY_OOP(constants->resolved_klass_at(index)->java_mirror());
1970
SET_STACK_OBJECT(constants->resolved_klass_at(index)->java_mirror(), 0);
1971
break;
1972
1973
case JVM_CONSTANT_UnresolvedClass:
1974
case JVM_CONSTANT_UnresolvedClassInError:
1975
CALL_VM(InterpreterRuntime::ldc(THREAD, wide), handle_exception);
1976
SET_STACK_OBJECT(THREAD->vm_result(), 0);
1977
THREAD->set_vm_result(NULL);
1978
break;
1979
1980
case JVM_CONSTANT_Dynamic:
1981
case JVM_CONSTANT_DynamicInError:
1982
{
1983
CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);
1984
oop result = THREAD->vm_result();
1985
VERIFY_OOP(result);
1986
1987
jvalue value;
1988
BasicType type = java_lang_boxing_object::get_value(result, &value);
1989
switch (type) {
1990
case T_FLOAT: SET_STACK_FLOAT(value.f, 0); break;
1991
case T_INT: SET_STACK_INT(value.i, 0); break;
1992
case T_SHORT: SET_STACK_INT(value.s, 0); break;
1993
case T_BYTE: SET_STACK_INT(value.b, 0); break;
1994
case T_CHAR: SET_STACK_INT(value.c, 0); break;
1995
case T_BOOLEAN: SET_STACK_INT(value.z, 0); break;
1996
default: ShouldNotReachHere();
1997
}
1998
1999
break;
2000
}
2001
2002
default: ShouldNotReachHere();
2003
}
2004
UPDATE_PC_AND_TOS_AND_CONTINUE(incr, 1);
2005
}
2006
2007
CASE(_ldc2_w):
2008
{
2009
u2 index = Bytes::get_Java_u2(pc+1);
2010
2011
ConstantPool* constants = METHOD->constants();
2012
switch (constants->tag_at(index).value()) {
2013
2014
case JVM_CONSTANT_Long:
2015
SET_STACK_LONG(constants->long_at(index), 1);
2016
break;
2017
2018
case JVM_CONSTANT_Double:
2019
SET_STACK_DOUBLE(constants->double_at(index), 1);
2020
break;
2021
2022
case JVM_CONSTANT_Dynamic:
2023
case JVM_CONSTANT_DynamicInError:
2024
{
2025
CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode), handle_exception);
2026
oop result = THREAD->vm_result();
2027
VERIFY_OOP(result);
2028
2029
jvalue value;
2030
BasicType type = java_lang_boxing_object::get_value(result, &value);
2031
switch (type) {
2032
case T_DOUBLE: SET_STACK_DOUBLE(value.d, 1); break;
2033
case T_LONG: SET_STACK_LONG(value.j, 1); break;
2034
default: ShouldNotReachHere();
2035
}
2036
2037
break;
2038
}
2039
2040
default: ShouldNotReachHere();
2041
}
2042
UPDATE_PC_AND_TOS_AND_CONTINUE(3, 2);
2043
}
2044
2045
CASE(_fast_aldc_w):
2046
CASE(_fast_aldc): {
2047
u2 index;
2048
int incr;
2049
if (opcode == Bytecodes::_fast_aldc) {
2050
index = pc[1];
2051
incr = 2;
2052
} else {
2053
index = Bytes::get_native_u2(pc+1);
2054
incr = 3;
2055
}
2056
2057
// We are resolved if the resolved_references array contains a non-null object (CallSite, etc.)
2058
// This kind of CP cache entry does not need to match the flags byte, because
2059
// there is a 1-1 relation between bytecode type and CP entry type.
2060
ConstantPool* constants = METHOD->constants();
2061
oop result = constants->resolved_references()->obj_at(index);
2062
if (result == NULL) {
2063
CALL_VM(InterpreterRuntime::resolve_ldc(THREAD, (Bytecodes::Code) opcode),
2064
handle_exception);
2065
result = THREAD->vm_result();
2066
}
2067
if (result == Universe::the_null_sentinel())
2068
result = NULL;
2069
2070
VERIFY_OOP(result);
2071
SET_STACK_OBJECT(result, 0);
2072
UPDATE_PC_AND_TOS_AND_CONTINUE(incr, 1);
2073
}
2074
2075
CASE(_invokedynamic): {
2076
2077
u4 index = Bytes::get_native_u4(pc+1);
2078
ConstantPoolCacheEntry* cache = cp->constant_pool()->invokedynamic_cp_cache_entry_at(index);
2079
2080
// We are resolved if the resolved_references array contains a non-null object (CallSite, etc.)
2081
// This kind of CP cache entry does not need to match the flags byte, because
2082
// there is a 1-1 relation between bytecode type and CP entry type.
2083
if (! cache->is_resolved((Bytecodes::Code) opcode)) {
2084
CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),
2085
handle_exception);
2086
cache = cp->constant_pool()->invokedynamic_cp_cache_entry_at(index);
2087
}
2088
2089
Method* method = cache->f1_as_method();
2090
if (VerifyOops) method->verify();
2091
2092
if (cache->has_appendix()) {
2093
constantPoolHandle cp(THREAD, METHOD->constants());
2094
SET_STACK_OBJECT(cache->appendix_if_resolved(cp), 0);
2095
MORE_STACK(1);
2096
}
2097
2098
istate->set_msg(call_method);
2099
istate->set_callee(method);
2100
istate->set_callee_entry_point(method->from_interpreted_entry());
2101
istate->set_bcp_advance(5);
2102
2103
UPDATE_PC_AND_RETURN(0); // I'll be back...
2104
}
2105
2106
CASE(_invokehandle): {
2107
2108
u2 index = Bytes::get_native_u2(pc+1);
2109
ConstantPoolCacheEntry* cache = cp->entry_at(index);
2110
2111
if (! cache->is_resolved((Bytecodes::Code) opcode)) {
2112
CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),
2113
handle_exception);
2114
cache = cp->entry_at(index);
2115
}
2116
2117
Method* method = cache->f1_as_method();
2118
if (VerifyOops) method->verify();
2119
2120
if (cache->has_appendix()) {
2121
constantPoolHandle cp(THREAD, METHOD->constants());
2122
SET_STACK_OBJECT(cache->appendix_if_resolved(cp), 0);
2123
MORE_STACK(1);
2124
}
2125
2126
istate->set_msg(call_method);
2127
istate->set_callee(method);
2128
istate->set_callee_entry_point(method->from_interpreted_entry());
2129
istate->set_bcp_advance(3);
2130
2131
UPDATE_PC_AND_RETURN(0); // I'll be back...
2132
}
2133
2134
CASE(_invokeinterface): {
2135
u2 index = Bytes::get_native_u2(pc+1);
2136
2137
// QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases
2138
// out so c++ compiler has a chance for constant prop to fold everything possible away.
2139
2140
ConstantPoolCacheEntry* cache = cp->entry_at(index);
2141
if (!cache->is_resolved((Bytecodes::Code)opcode)) {
2142
CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),
2143
handle_exception);
2144
cache = cp->entry_at(index);
2145
}
2146
2147
istate->set_msg(call_method);
2148
2149
// Special case of invokeinterface called for virtual method of
2150
// java.lang.Object. See cpCache.cpp for details.
2151
Method* callee = NULL;
2152
if (cache->is_forced_virtual()) {
2153
CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
2154
if (cache->is_vfinal()) {
2155
callee = cache->f2_as_vfinal_method();
2156
} else {
2157
// Get receiver.
2158
int parms = cache->parameter_size();
2159
// Same comments as invokevirtual apply here.
2160
oop rcvr = STACK_OBJECT(-parms);
2161
VERIFY_OOP(rcvr);
2162
Klass* rcvrKlass = rcvr->klass();
2163
callee = (Method*) rcvrKlass->method_at_vtable(cache->f2_as_index());
2164
}
2165
} else if (cache->is_vfinal()) {
2166
// private interface method invocations
2167
//
2168
// Ensure receiver class actually implements
2169
// the resolved interface class. The link resolver
2170
// does this, but only for the first time this
2171
// interface is being called.
2172
int parms = cache->parameter_size();
2173
oop rcvr = STACK_OBJECT(-parms);
2174
CHECK_NULL(rcvr);
2175
Klass* recv_klass = rcvr->klass();
2176
Klass* resolved_klass = cache->f1_as_klass();
2177
if (!recv_klass->is_subtype_of(resolved_klass)) {
2178
ResourceMark rm(THREAD);
2179
char buf[200];
2180
jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s",
2181
recv_klass->external_name(),
2182
resolved_klass->external_name());
2183
VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
2184
}
2185
callee = cache->f2_as_vfinal_method();
2186
}
2187
if (callee != NULL) {
2188
istate->set_callee(callee);
2189
istate->set_callee_entry_point(callee->from_interpreted_entry());
2190
if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {
2191
istate->set_callee_entry_point(callee->interpreter_entry());
2192
}
2193
istate->set_bcp_advance(5);
2194
UPDATE_PC_AND_RETURN(0); // I'll be back...
2195
}
2196
2197
// this could definitely be cleaned up QQQ
2198
Method *interface_method = cache->f2_as_interface_method();
2199
InstanceKlass* iclass = interface_method->method_holder();
2200
2201
// get receiver
2202
int parms = cache->parameter_size();
2203
oop rcvr = STACK_OBJECT(-parms);
2204
CHECK_NULL(rcvr);
2205
InstanceKlass* int2 = (InstanceKlass*) rcvr->klass();
2206
2207
// Receiver subtype check against resolved interface klass (REFC).
2208
{
2209
Klass* refc = cache->f1_as_klass();
2210
itableOffsetEntry* scan;
2211
for (scan = (itableOffsetEntry*) int2->start_of_itable();
2212
scan->interface_klass() != NULL;
2213
scan++) {
2214
if (scan->interface_klass() == refc) {
2215
break;
2216
}
2217
}
2218
// Check that the entry is non-null. A null entry means
2219
// that the receiver class doesn't implement the
2220
// interface, and wasn't the same as when the caller was
2221
// compiled.
2222
if (scan->interface_klass() == NULL) {
2223
VM_JAVA_ERROR(vmSymbols::java_lang_IncompatibleClassChangeError(), "");
2224
}
2225
}
2226
2227
itableOffsetEntry* ki = (itableOffsetEntry*) int2->start_of_itable();
2228
int i;
2229
for ( i = 0 ; i < int2->itable_length() ; i++, ki++ ) {
2230
if (ki->interface_klass() == iclass) break;
2231
}
2232
// If the interface isn't found, this class doesn't implement this
2233
// interface. The link resolver checks this but only for the first
2234
// time this interface is called.
2235
if (i == int2->itable_length()) {
2236
CALL_VM(InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose(THREAD, rcvr->klass(), iclass),
2237
handle_exception);
2238
}
2239
int mindex = interface_method->itable_index();
2240
2241
itableMethodEntry* im = ki->first_method_entry(rcvr->klass());
2242
callee = im[mindex].method();
2243
if (callee == NULL) {
2244
CALL_VM(InterpreterRuntime::throw_AbstractMethodErrorVerbose(THREAD, rcvr->klass(), interface_method),
2245
handle_exception);
2246
}
2247
2248
istate->set_callee(callee);
2249
istate->set_callee_entry_point(callee->from_interpreted_entry());
2250
if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {
2251
istate->set_callee_entry_point(callee->interpreter_entry());
2252
}
2253
istate->set_bcp_advance(5);
2254
UPDATE_PC_AND_RETURN(0); // I'll be back...
2255
}
2256
2257
CASE(_invokevirtual):
2258
CASE(_invokespecial):
2259
CASE(_invokestatic): {
2260
u2 index = Bytes::get_native_u2(pc+1);
2261
2262
ConstantPoolCacheEntry* cache = cp->entry_at(index);
2263
// QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases
2264
// out so c++ compiler has a chance for constant prop to fold everything possible away.
2265
2266
if (!cache->is_resolved((Bytecodes::Code)opcode)) {
2267
CALL_VM(InterpreterRuntime::resolve_from_cache(THREAD, (Bytecodes::Code)opcode),
2268
handle_exception);
2269
cache = cp->entry_at(index);
2270
}
2271
2272
istate->set_msg(call_method);
2273
{
2274
Method* callee;
2275
if ((Bytecodes::Code)opcode == Bytecodes::_invokevirtual) {
2276
CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
2277
if (cache->is_vfinal()) {
2278
callee = cache->f2_as_vfinal_method();
2279
} else {
2280
// get receiver
2281
int parms = cache->parameter_size();
2282
// this works but needs a resourcemark and seems to create a vtable on every call:
2283
// Method* callee = rcvr->klass()->vtable()->method_at(cache->f2_as_index());
2284
//
2285
// this fails with an assert
2286
// InstanceKlass* rcvrKlass = InstanceKlass::cast(STACK_OBJECT(-parms)->klass());
2287
// but this works
2288
oop rcvr = STACK_OBJECT(-parms);
2289
VERIFY_OOP(rcvr);
2290
Klass* rcvrKlass = rcvr->klass();
2291
/*
2292
Executing this code in java.lang.String:
2293
public String(char value[]) {
2294
this.count = value.length;
2295
this.value = (char[])value.clone();
2296
}
2297
2298
a find on rcvr->klass() reports:
2299
{type array char}{type array class}
2300
- klass: {other class}
2301
2302
but using InstanceKlass::cast(STACK_OBJECT(-parms)->klass()) causes in assertion failure
2303
because rcvr->klass()->is_instance_klass() == 0
2304
However it seems to have a vtable in the right location. Huh?
2305
Because vtables have the same offset for ArrayKlass and InstanceKlass.
2306
*/
2307
callee = (Method*) rcvrKlass->method_at_vtable(cache->f2_as_index());
2308
}
2309
} else {
2310
if ((Bytecodes::Code)opcode == Bytecodes::_invokespecial) {
2311
CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
2312
}
2313
callee = cache->f1_as_method();
2314
}
2315
2316
istate->set_callee(callee);
2317
istate->set_callee_entry_point(callee->from_interpreted_entry());
2318
if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {
2319
istate->set_callee_entry_point(callee->interpreter_entry());
2320
}
2321
istate->set_bcp_advance(3);
2322
UPDATE_PC_AND_RETURN(0); // I'll be back...
2323
}
2324
}
2325
2326
/* Allocate memory for a new java object. */
2327
2328
CASE(_newarray): {
2329
BasicType atype = (BasicType) *(pc+1);
2330
jint size = STACK_INT(-1);
2331
CALL_VM(InterpreterRuntime::newarray(THREAD, atype, size),
2332
handle_exception);
2333
// Must prevent reordering of stores for object initialization
2334
// with stores that publish the new object.
2335
OrderAccess::storestore();
2336
SET_STACK_OBJECT(THREAD->vm_result(), -1);
2337
THREAD->set_vm_result(NULL);
2338
2339
UPDATE_PC_AND_CONTINUE(2);
2340
}
2341
2342
/* Throw an exception. */
2343
2344
CASE(_athrow): {
2345
oop except_oop = STACK_OBJECT(-1);
2346
CHECK_NULL(except_oop);
2347
// set pending_exception so we use common code
2348
THREAD->set_pending_exception(except_oop, NULL, 0);
2349
goto handle_exception;
2350
}
2351
2352
/* goto and jsr. They are exactly the same except jsr pushes
2353
* the address of the next instruction first.
2354
*/
2355
2356
CASE(_jsr): {
2357
/* push bytecode index on stack */
2358
SET_STACK_ADDR(((address)pc - (intptr_t)(istate->method()->code_base()) + 3), 0);
2359
MORE_STACK(1);
2360
/* FALL THROUGH */
2361
}
2362
2363
CASE(_goto):
2364
{
2365
int16_t offset = (int16_t)Bytes::get_Java_u2(pc + 1);
2366
address branch_pc = pc;
2367
UPDATE_PC(offset);
2368
DO_BACKEDGE_CHECKS(offset, branch_pc);
2369
CONTINUE;
2370
}
2371
2372
CASE(_jsr_w): {
2373
/* push return address on the stack */
2374
SET_STACK_ADDR(((address)pc - (intptr_t)(istate->method()->code_base()) + 5), 0);
2375
MORE_STACK(1);
2376
/* FALL THROUGH */
2377
}
2378
2379
CASE(_goto_w):
2380
{
2381
int32_t offset = Bytes::get_Java_u4(pc + 1);
2382
address branch_pc = pc;
2383
UPDATE_PC(offset);
2384
DO_BACKEDGE_CHECKS(offset, branch_pc);
2385
CONTINUE;
2386
}
2387
2388
/* return from a jsr or jsr_w */
2389
2390
CASE(_ret): {
2391
pc = istate->method()->code_base() + (intptr_t)(LOCALS_ADDR(pc[1]));
2392
UPDATE_PC_AND_CONTINUE(0);
2393
}
2394
2395
/* debugger breakpoint */
2396
2397
CASE(_breakpoint): {
2398
Bytecodes::Code original_bytecode;
2399
DECACHE_STATE();
2400
SET_LAST_JAVA_FRAME();
2401
original_bytecode = InterpreterRuntime::get_original_bytecode_at(THREAD,
2402
METHOD, pc);
2403
RESET_LAST_JAVA_FRAME();
2404
CACHE_STATE();
2405
if (THREAD->has_pending_exception()) goto handle_exception;
2406
CALL_VM(InterpreterRuntime::_breakpoint(THREAD, METHOD, pc),
2407
handle_exception);
2408
2409
opcode = (jubyte)original_bytecode;
2410
goto opcode_switch;
2411
}
2412
2413
DEFAULT:
2414
fatal("Unimplemented opcode %d = %s", opcode,
2415
Bytecodes::name((Bytecodes::Code)opcode));
2416
goto finish;
2417
2418
} /* switch(opc) */
2419
2420
2421
#ifdef USELABELS
2422
check_for_exception:
2423
#endif
2424
{
2425
if (!THREAD->has_pending_exception()) {
2426
CONTINUE;
2427
}
2428
/* We will be gcsafe soon, so flush our state. */
2429
DECACHE_PC();
2430
goto handle_exception;
2431
}
2432
do_continue: ;
2433
2434
} /* while (1) interpreter loop */
2435
2436
2437
// An exception exists in the thread state see whether this activation can handle it
2438
handle_exception: {
2439
2440
HandleMarkCleaner __hmc(THREAD);
2441
Handle except_oop(THREAD, THREAD->pending_exception());
2442
// Prevent any subsequent HandleMarkCleaner in the VM
2443
// from freeing the except_oop handle.
2444
HandleMark __hm(THREAD);
2445
2446
THREAD->clear_pending_exception();
2447
assert(except_oop() != NULL, "No exception to process");
2448
intptr_t continuation_bci;
2449
// expression stack is emptied
2450
topOfStack = istate->stack_base() - Interpreter::stackElementWords;
2451
CALL_VM(continuation_bci = (intptr_t)InterpreterRuntime::exception_handler_for_exception(THREAD, except_oop()),
2452
handle_exception);
2453
2454
except_oop = Handle(THREAD, THREAD->vm_result());
2455
THREAD->set_vm_result(NULL);
2456
if (continuation_bci >= 0) {
2457
// Place exception on top of stack
2458
SET_STACK_OBJECT(except_oop(), 0);
2459
MORE_STACK(1);
2460
pc = METHOD->code_base() + continuation_bci;
2461
if (log_is_enabled(Info, exceptions)) {
2462
ResourceMark rm(THREAD);
2463
stringStream tempst;
2464
tempst.print("interpreter method <%s>\n"
2465
" at bci %d, continuing at %d for thread " INTPTR_FORMAT,
2466
METHOD->print_value_string(),
2467
(int)(istate->bcp() - METHOD->code_base()),
2468
(int)continuation_bci, p2i(THREAD));
2469
Exceptions::log_exception(except_oop, tempst.as_string());
2470
}
2471
// for AbortVMOnException flag
2472
Exceptions::debug_check_abort(except_oop);
2473
goto run;
2474
}
2475
if (log_is_enabled(Info, exceptions)) {
2476
ResourceMark rm;
2477
stringStream tempst;
2478
tempst.print("interpreter method <%s>\n"
2479
" at bci %d, unwinding for thread " INTPTR_FORMAT,
2480
METHOD->print_value_string(),
2481
(int)(istate->bcp() - METHOD->code_base()),
2482
p2i(THREAD));
2483
Exceptions::log_exception(except_oop, tempst.as_string());
2484
}
2485
// for AbortVMOnException flag
2486
Exceptions::debug_check_abort(except_oop);
2487
2488
// No handler in this activation, unwind and try again
2489
THREAD->set_pending_exception(except_oop(), NULL, 0);
2490
goto handle_return;
2491
} // handle_exception:
2492
2493
// Return from an interpreter invocation with the result of the interpretation
2494
// on the top of the Java Stack (or a pending exception)
2495
2496
handle_Pop_Frame: {
2497
2498
// We don't really do anything special here except we must be aware
2499
// that we can get here without ever locking the method (if sync).
2500
// Also we skip the notification of the exit.
2501
2502
istate->set_msg(popping_frame);
2503
// Clear pending so while the pop is in process
2504
// we don't start another one if a call_vm is done.
2505
THREAD->clear_popframe_condition();
2506
// Let interpreter (only) see the we're in the process of popping a frame
2507
THREAD->set_pop_frame_in_process();
2508
2509
goto handle_return;
2510
2511
} // handle_Pop_Frame
2512
2513
// ForceEarlyReturn ends a method, and returns to the caller with a return value
2514
// given by the invoker of the early return.
2515
handle_Early_Return: {
2516
2517
istate->set_msg(early_return);
2518
2519
// Clear expression stack.
2520
topOfStack = istate->stack_base() - Interpreter::stackElementWords;
2521
2522
JvmtiThreadState *ts = THREAD->jvmti_thread_state();
2523
2524
// Push the value to be returned.
2525
switch (istate->method()->result_type()) {
2526
case T_BOOLEAN:
2527
case T_SHORT:
2528
case T_BYTE:
2529
case T_CHAR:
2530
case T_INT:
2531
SET_STACK_INT(ts->earlyret_value().i, 0);
2532
MORE_STACK(1);
2533
break;
2534
case T_LONG:
2535
SET_STACK_LONG(ts->earlyret_value().j, 1);
2536
MORE_STACK(2);
2537
break;
2538
case T_FLOAT:
2539
SET_STACK_FLOAT(ts->earlyret_value().f, 0);
2540
MORE_STACK(1);
2541
break;
2542
case T_DOUBLE:
2543
SET_STACK_DOUBLE(ts->earlyret_value().d, 1);
2544
MORE_STACK(2);
2545
break;
2546
case T_ARRAY:
2547
case T_OBJECT:
2548
SET_STACK_OBJECT(ts->earlyret_oop(), 0);
2549
MORE_STACK(1);
2550
break;
2551
default:
2552
ShouldNotReachHere();
2553
}
2554
2555
ts->clr_earlyret_value();
2556
ts->set_earlyret_oop(NULL);
2557
ts->clr_earlyret_pending();
2558
2559
// Fall through to handle_return.
2560
2561
} // handle_Early_Return
2562
2563
handle_return: {
2564
// A storestore barrier is required to order initialization of
2565
// final fields with publishing the reference to the object that
2566
// holds the field. Without the barrier the value of final fields
2567
// can be observed to change.
2568
OrderAccess::storestore();
2569
2570
DECACHE_STATE();
2571
2572
bool suppress_error = istate->msg() == popping_frame || istate->msg() == early_return;
2573
bool suppress_exit_event = THREAD->has_pending_exception() || istate->msg() == popping_frame;
2574
Handle original_exception(THREAD, THREAD->pending_exception());
2575
Handle illegal_state_oop(THREAD, NULL);
2576
2577
// We'd like a HandleMark here to prevent any subsequent HandleMarkCleaner
2578
// in any following VM entries from freeing our live handles, but illegal_state_oop
2579
// isn't really allocated yet and so doesn't become live until later and
2580
// in unpredicatable places. Instead we must protect the places where we enter the
2581
// VM. It would be much simpler (and safer) if we could allocate a real handle with
2582
// a NULL oop in it and then overwrite the oop later as needed. This isn't
2583
// unfortunately isn't possible.
2584
2585
if (THREAD->has_pending_exception()) {
2586
THREAD->clear_pending_exception();
2587
}
2588
2589
//
2590
// As far as we are concerned we have returned. If we have a pending exception
2591
// that will be returned as this invocation's result. However if we get any
2592
// exception(s) while checking monitor state one of those IllegalMonitorStateExceptions
2593
// will be our final result (i.e. monitor exception trumps a pending exception).
2594
//
2595
2596
// If we never locked the method (or really passed the point where we would have),
2597
// there is no need to unlock it (or look for other monitors), since that
2598
// could not have happened.
2599
2600
if (THREAD->do_not_unlock()) {
2601
2602
// Never locked, reset the flag now because obviously any caller must
2603
// have passed their point of locking for us to have gotten here.
2604
2605
THREAD->clr_do_not_unlock();
2606
} else {
2607
// At this point we consider that we have returned. We now check that the
2608
// locks were properly block structured. If we find that they were not
2609
// used properly we will return with an illegal monitor exception.
2610
// The exception is checked by the caller not the callee since this
2611
// checking is considered to be part of the invocation and therefore
2612
// in the callers scope (JVM spec 8.13).
2613
//
2614
// Another weird thing to watch for is if the method was locked
2615
// recursively and then not exited properly. This means we must
2616
// examine all the entries in reverse time(and stack) order and
2617
// unlock as we find them. If we find the method monitor before
2618
// we are at the initial entry then we should throw an exception.
2619
// It is not clear the template based interpreter does this
2620
// correctly
2621
2622
BasicObjectLock* base = istate->monitor_base();
2623
BasicObjectLock* end = (BasicObjectLock*) istate->stack_base();
2624
bool method_unlock_needed = METHOD->is_synchronized();
2625
// We know the initial monitor was used for the method don't check that
2626
// slot in the loop
2627
if (method_unlock_needed) base--;
2628
2629
// Check all the monitors to see they are unlocked. Install exception if found to be locked.
2630
while (end < base) {
2631
oop lockee = end->obj();
2632
if (lockee != NULL) {
2633
BasicLock* lock = end->lock();
2634
markWord header = lock->displaced_header();
2635
end->set_obj(NULL);
2636
2637
assert(!UseBiasedLocking, "Not implemented");
2638
2639
// If it isn't recursive we either must swap old header or call the runtime
2640
if (header.to_pointer() != NULL) {
2641
markWord old_header = markWord::encode(lock);
2642
if (lockee->cas_set_mark(header, old_header) != old_header) {
2643
// restore object for the slow case
2644
end->set_obj(lockee);
2645
InterpreterRuntime::monitorexit(end);
2646
}
2647
}
2648
2649
// One error is plenty
2650
if (illegal_state_oop() == NULL && !suppress_error) {
2651
{
2652
// Prevent any HandleMarkCleaner from freeing our live handles
2653
HandleMark __hm(THREAD);
2654
CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));
2655
}
2656
assert(THREAD->has_pending_exception(), "Lost our exception!");
2657
illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
2658
THREAD->clear_pending_exception();
2659
}
2660
}
2661
end++;
2662
}
2663
// Unlock the method if needed
2664
if (method_unlock_needed) {
2665
if (base->obj() == NULL) {
2666
// The method is already unlocked this is not good.
2667
if (illegal_state_oop() == NULL && !suppress_error) {
2668
{
2669
// Prevent any HandleMarkCleaner from freeing our live handles
2670
HandleMark __hm(THREAD);
2671
CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));
2672
}
2673
assert(THREAD->has_pending_exception(), "Lost our exception!");
2674
illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
2675
THREAD->clear_pending_exception();
2676
}
2677
} else {
2678
//
2679
// The initial monitor is always used for the method
2680
// However if that slot is no longer the oop for the method it was unlocked
2681
// and reused by something that wasn't unlocked!
2682
//
2683
// deopt can come in with rcvr dead because c2 knows
2684
// its value is preserved in the monitor. So we can't use locals[0] at all
2685
// and must use first monitor slot.
2686
//
2687
oop rcvr = base->obj();
2688
if (rcvr == NULL) {
2689
if (!suppress_error) {
2690
VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "");
2691
illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
2692
THREAD->clear_pending_exception();
2693
}
2694
} else if (UseHeavyMonitors) {
2695
InterpreterRuntime::monitorexit(base);
2696
if (THREAD->has_pending_exception()) {
2697
if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
2698
THREAD->clear_pending_exception();
2699
}
2700
} else {
2701
BasicLock* lock = base->lock();
2702
markWord header = lock->displaced_header();
2703
base->set_obj(NULL);
2704
2705
assert(!UseBiasedLocking, "Not implemented");
2706
2707
// If it isn't recursive we either must swap old header or call the runtime
2708
if (header.to_pointer() != NULL) {
2709
markWord old_header = markWord::encode(lock);
2710
if (rcvr->cas_set_mark(header, old_header) != old_header) {
2711
// restore object for the slow case
2712
base->set_obj(rcvr);
2713
InterpreterRuntime::monitorexit(base);
2714
if (THREAD->has_pending_exception()) {
2715
if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
2716
THREAD->clear_pending_exception();
2717
}
2718
}
2719
}
2720
}
2721
}
2722
}
2723
}
2724
// Clear the do_not_unlock flag now.
2725
THREAD->clr_do_not_unlock();
2726
2727
//
2728
// Notify jvmti/jvmdi
2729
//
2730
// NOTE: we do not notify a method_exit if we have a pending exception,
2731
// including an exception we generate for unlocking checks. In the former
2732
// case, JVMDI has already been notified by our call for the exception handler
2733
// and in both cases as far as JVMDI is concerned we have already returned.
2734
// If we notify it again JVMDI will be all confused about how many frames
2735
// are still on the stack (4340444).
2736
//
2737
// NOTE Further! It turns out the the JVMTI spec in fact expects to see
2738
// method_exit events whenever we leave an activation unless it was done
2739
// for popframe. This is nothing like jvmdi. However we are passing the
2740
// tests at the moment (apparently because they are jvmdi based) so rather
2741
// than change this code and possibly fail tests we will leave it alone
2742
// (with this note) in anticipation of changing the vm and the tests
2743
// simultaneously.
2744
2745
suppress_exit_event = suppress_exit_event || illegal_state_oop() != NULL;
2746
2747
// Whenever JVMTI puts a thread in interp_only_mode, method
2748
// entry/exit events are sent for that thread to track stack depth.
2749
2750
if (JVMTI_ENABLED && !suppress_exit_event && THREAD->is_interp_only_mode()) {
2751
// Prevent any HandleMarkCleaner from freeing our live handles
2752
HandleMark __hm(THREAD);
2753
CALL_VM_NOCHECK(InterpreterRuntime::post_method_exit(THREAD));
2754
}
2755
2756
//
2757
// See if we are returning any exception
2758
// A pending exception that was pending prior to a possible popping frame
2759
// overrides the popping frame.
2760
//
2761
assert(!suppress_error || (suppress_error && illegal_state_oop() == NULL), "Error was not suppressed");
2762
if (illegal_state_oop() != NULL || original_exception() != NULL) {
2763
// Inform the frame manager we have no result.
2764
istate->set_msg(throwing_exception);
2765
if (illegal_state_oop() != NULL)
2766
THREAD->set_pending_exception(illegal_state_oop(), NULL, 0);
2767
else
2768
THREAD->set_pending_exception(original_exception(), NULL, 0);
2769
UPDATE_PC_AND_RETURN(0);
2770
}
2771
2772
if (istate->msg() == popping_frame) {
2773
// Make it simpler on the assembly code and set the message for the frame pop.
2774
// returns
2775
if (istate->prev() == NULL) {
2776
// We must be returning to a deoptimized frame (because popframe only happens between
2777
// two interpreted frames). We need to save the current arguments in C heap so that
2778
// the deoptimized frame when it restarts can copy the arguments to its expression
2779
// stack and re-execute the call. We also have to notify deoptimization that this
2780
// has occurred and to pick the preserved args copy them to the deoptimized frame's
2781
// java expression stack. Yuck.
2782
//
2783
THREAD->popframe_preserve_args(in_ByteSize(METHOD->size_of_parameters() * wordSize),
2784
LOCALS_SLOT(METHOD->size_of_parameters() - 1));
2785
THREAD->set_popframe_condition_bit(JavaThread::popframe_force_deopt_reexecution_bit);
2786
}
2787
} else {
2788
istate->set_msg(return_from_method);
2789
}
2790
2791
// Normal return
2792
// Advance the pc and return to frame manager
2793
UPDATE_PC_AND_RETURN(1);
2794
} /* handle_return: */
2795
2796
// This is really a fatal error return
2797
2798
finish:
2799
DECACHE_TOS();
2800
DECACHE_PC();
2801
2802
return;
2803
}
2804
2805
// This constructor should only be used to contruct the object to signal
2806
// interpreter initialization. All other instances should be created by
2807
// the frame manager.
2808
BytecodeInterpreter::BytecodeInterpreter(messages msg) {
2809
if (msg != initialize) ShouldNotReachHere();
2810
_msg = msg;
2811
_self_link = this;
2812
_prev_link = NULL;
2813
}
2814
2815
void BytecodeInterpreter::astore(intptr_t* tos, int stack_offset,
2816
intptr_t* locals, int locals_offset) {
2817
intptr_t value = tos[Interpreter::expr_index_at(-stack_offset)];
2818
locals[Interpreter::local_index_at(-locals_offset)] = value;
2819
}
2820
2821
void BytecodeInterpreter::copy_stack_slot(intptr_t *tos, int from_offset,
2822
int to_offset) {
2823
tos[Interpreter::expr_index_at(-to_offset)] =
2824
(intptr_t)tos[Interpreter::expr_index_at(-from_offset)];
2825
}
2826
2827
void BytecodeInterpreter::dup(intptr_t *tos) {
2828
copy_stack_slot(tos, -1, 0);
2829
}
2830
2831
void BytecodeInterpreter::dup2(intptr_t *tos) {
2832
copy_stack_slot(tos, -2, 0);
2833
copy_stack_slot(tos, -1, 1);
2834
}
2835
2836
void BytecodeInterpreter::dup_x1(intptr_t *tos) {
2837
/* insert top word two down */
2838
copy_stack_slot(tos, -1, 0);
2839
copy_stack_slot(tos, -2, -1);
2840
copy_stack_slot(tos, 0, -2);
2841
}
2842
2843
void BytecodeInterpreter::dup_x2(intptr_t *tos) {
2844
/* insert top word three down */
2845
copy_stack_slot(tos, -1, 0);
2846
copy_stack_slot(tos, -2, -1);
2847
copy_stack_slot(tos, -3, -2);
2848
copy_stack_slot(tos, 0, -3);
2849
}
2850
void BytecodeInterpreter::dup2_x1(intptr_t *tos) {
2851
/* insert top 2 slots three down */
2852
copy_stack_slot(tos, -1, 1);
2853
copy_stack_slot(tos, -2, 0);
2854
copy_stack_slot(tos, -3, -1);
2855
copy_stack_slot(tos, 1, -2);
2856
copy_stack_slot(tos, 0, -3);
2857
}
2858
void BytecodeInterpreter::dup2_x2(intptr_t *tos) {
2859
/* insert top 2 slots four down */
2860
copy_stack_slot(tos, -1, 1);
2861
copy_stack_slot(tos, -2, 0);
2862
copy_stack_slot(tos, -3, -1);
2863
copy_stack_slot(tos, -4, -2);
2864
copy_stack_slot(tos, 1, -3);
2865
copy_stack_slot(tos, 0, -4);
2866
}
2867
2868
2869
void BytecodeInterpreter::swap(intptr_t *tos) {
2870
// swap top two elements
2871
intptr_t val = tos[Interpreter::expr_index_at(1)];
2872
// Copy -2 entry to -1
2873
copy_stack_slot(tos, -2, -1);
2874
// Store saved -1 entry into -2
2875
tos[Interpreter::expr_index_at(2)] = val;
2876
}
2877
// --------------------------------------------------------------------------------
2878
// Non-product code
2879
#ifndef PRODUCT
2880
2881
const char* BytecodeInterpreter::C_msg(BytecodeInterpreter::messages msg) {
2882
switch (msg) {
2883
case BytecodeInterpreter::no_request: return("no_request");
2884
case BytecodeInterpreter::initialize: return("initialize");
2885
// status message to C++ interpreter
2886
case BytecodeInterpreter::method_entry: return("method_entry");
2887
case BytecodeInterpreter::method_resume: return("method_resume");
2888
case BytecodeInterpreter::got_monitors: return("got_monitors");
2889
case BytecodeInterpreter::rethrow_exception: return("rethrow_exception");
2890
// requests to frame manager from C++ interpreter
2891
case BytecodeInterpreter::call_method: return("call_method");
2892
case BytecodeInterpreter::return_from_method: return("return_from_method");
2893
case BytecodeInterpreter::more_monitors: return("more_monitors");
2894
case BytecodeInterpreter::throwing_exception: return("throwing_exception");
2895
case BytecodeInterpreter::popping_frame: return("popping_frame");
2896
case BytecodeInterpreter::do_osr: return("do_osr");
2897
// deopt
2898
case BytecodeInterpreter::deopt_resume: return("deopt_resume");
2899
case BytecodeInterpreter::deopt_resume2: return("deopt_resume2");
2900
default: return("BAD MSG");
2901
}
2902
}
2903
void
2904
BytecodeInterpreter::print() {
2905
tty->print_cr("thread: " INTPTR_FORMAT, (uintptr_t) this->_thread);
2906
tty->print_cr("bcp: " INTPTR_FORMAT, (uintptr_t) this->_bcp);
2907
tty->print_cr("locals: " INTPTR_FORMAT, (uintptr_t) this->_locals);
2908
tty->print_cr("constants: " INTPTR_FORMAT, (uintptr_t) this->_constants);
2909
{
2910
ResourceMark rm;
2911
char *method_name = _method->name_and_sig_as_C_string();
2912
tty->print_cr("method: " INTPTR_FORMAT "[ %s ]", (uintptr_t) this->_method, method_name);
2913
}
2914
tty->print_cr("stack: " INTPTR_FORMAT, (uintptr_t) this->_stack);
2915
tty->print_cr("msg: %s", C_msg(this->_msg));
2916
tty->print_cr("result_to_call._callee: " INTPTR_FORMAT, (uintptr_t) this->_result._to_call._callee);
2917
tty->print_cr("result_to_call._callee_entry_point: " INTPTR_FORMAT, (uintptr_t) this->_result._to_call._callee_entry_point);
2918
tty->print_cr("result_to_call._bcp_advance: %d ", this->_result._to_call._bcp_advance);
2919
tty->print_cr("osr._osr_buf: " INTPTR_FORMAT, (uintptr_t) this->_result._osr._osr_buf);
2920
tty->print_cr("osr._osr_entry: " INTPTR_FORMAT, (uintptr_t) this->_result._osr._osr_entry);
2921
tty->print_cr("prev_link: " INTPTR_FORMAT, (uintptr_t) this->_prev_link);
2922
tty->print_cr("native_mirror: " INTPTR_FORMAT, (uintptr_t) p2i(this->_oop_temp));
2923
tty->print_cr("stack_base: " INTPTR_FORMAT, (uintptr_t) this->_stack_base);
2924
tty->print_cr("stack_limit: " INTPTR_FORMAT, (uintptr_t) this->_stack_limit);
2925
tty->print_cr("monitor_base: " INTPTR_FORMAT, (uintptr_t) this->_monitor_base);
2926
tty->print_cr("self_link: " INTPTR_FORMAT, (uintptr_t) this->_self_link);
2927
}
2928
2929
extern "C" {
2930
void PI(uintptr_t arg) {
2931
((BytecodeInterpreter*)arg)->print();
2932
}
2933
}
2934
#endif // PRODUCT
2935
2936