Wed, 03 Jul 2019 20:42:37 +0800
Merge
1 /*
2 * Copyright (c) 2002, 2012, 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 */
25 /*
26 * This file has been modified by Loongson Technology in 2015. These
27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
28 * available on the same license terms set forth above.
29 */
31 #ifndef SHARE_VM_INTERPRETER_BYTECODEINTERPRETER_HPP
32 #define SHARE_VM_INTERPRETER_BYTECODEINTERPRETER_HPP
34 #include "memory/allocation.hpp"
35 #include "oops/methodData.hpp"
36 #include "oops/method.hpp"
37 #include "runtime/basicLock.hpp"
38 #include "runtime/frame.hpp"
39 #include "runtime/globals.hpp"
40 #include "utilities/globalDefinitions.hpp"
41 #ifdef TARGET_ARCH_x86
42 # include "bytes_x86.hpp"
43 #endif
44 #ifdef TARGET_ARCH_mips
45 # include "bytes_mips.hpp"
46 #endif
47 #ifdef TARGET_ARCH_sparc
48 # include "bytes_sparc.hpp"
49 #endif
50 #ifdef TARGET_ARCH_zero
51 # include "bytes_zero.hpp"
52 #endif
53 #ifdef TARGET_ARCH_arm
54 # include "bytes_arm.hpp"
55 #endif
56 #ifdef TARGET_ARCH_ppc
57 # include "bytes_ppc.hpp"
58 #endif
60 #ifdef CC_INTERP
62 // JavaStack Implementation
63 #define MORE_STACK(count) \
64 (topOfStack -= ((count) * Interpreter::stackElementWords))
66 // CVM definitions find hotspot equivalents...
68 union VMJavaVal64 {
69 jlong l;
70 jdouble d;
71 uint32_t v[2];
72 };
75 typedef class BytecodeInterpreter* interpreterState;
77 struct call_message {
78 class Method* _callee; // method to call during call_method request
79 address _callee_entry_point; // address to jump to for call_method request
80 int _bcp_advance; // size of the invoke bytecode operation
81 };
83 struct osr_message {
84 address _osr_buf; // the osr buffer
85 address _osr_entry; // the entry to the osr method
86 };
88 struct osr_result {
89 nmethod* nm; // osr nmethod
90 address return_addr; // osr blob return address
91 };
93 // Result returned to frame manager
94 union frame_manager_message {
95 call_message _to_call; // describes callee
96 osr_message _osr; // describes the osr
97 osr_result _osr_result; // result of OSR request
98 };
100 class BytecodeInterpreter : StackObj {
101 friend class SharedRuntime;
102 friend class AbstractInterpreterGenerator;
103 friend class CppInterpreterGenerator;
104 friend class InterpreterGenerator;
105 friend class InterpreterMacroAssembler;
106 friend class frame;
107 friend class VMStructs;
109 public:
110 enum messages {
111 no_request = 0, // unused
112 initialize, // Perform one time interpreter initializations (assumes all switches set)
113 // status message to C++ interpreter
114 method_entry, // initial method entry to interpreter
115 method_resume, // frame manager response to return_from_method request (assuming a frame to resume)
116 deopt_resume, // returning from a native call into a deopted frame
117 deopt_resume2, // deopt resume as a result of a PopFrame
118 got_monitors, // frame manager response to more_monitors request
119 rethrow_exception, // unwinding and throwing exception
120 // requests to frame manager from C++ interpreter
121 call_method, // request for new frame from interpreter, manager responds with method_entry
122 return_from_method, // request from interpreter to unwind, manager responds with method_continue
123 more_monitors, // need a new monitor
124 throwing_exception, // unwind stack and rethrow
125 popping_frame, // unwind call and retry call
126 do_osr, // request this invocation be OSR's
127 early_return // early return as commanded by jvmti
128 };
130 private:
131 JavaThread* _thread; // the vm's java thread pointer
132 address _bcp; // instruction pointer
133 intptr_t* _locals; // local variable pointer
134 ConstantPoolCache* _constants; // constant pool cache
135 Method* _method; // method being executed
136 DataLayout* _mdx; // compiler profiling data for current bytecode
137 intptr_t* _stack; // expression stack
138 messages _msg; // frame manager <-> interpreter message
139 frame_manager_message _result; // result to frame manager
140 interpreterState _prev_link; // previous interpreter state
141 oop _oop_temp; // mirror for interpreted native, null otherwise
142 intptr_t* _stack_base; // base of expression stack
143 intptr_t* _stack_limit; // limit of expression stack
144 BasicObjectLock* _monitor_base; // base of monitors on the native stack
147 public:
148 // Constructor is only used by the initialization step. All other instances are created
149 // by the frame manager.
150 BytecodeInterpreter(messages msg);
152 //
153 // Deoptimization support
154 //
155 static void layout_interpreterState(interpreterState to_fill,
156 frame* caller,
157 frame* interpreter_frame,
158 Method* method,
159 intptr_t* locals,
160 intptr_t* stack,
161 intptr_t* stack_base,
162 intptr_t* monitor_base,
163 intptr_t* frame_bottom,
164 bool top_frame);
166 /*
167 * Generic 32-bit wide "Java slot" definition. This type occurs
168 * in operand stacks, Java locals, object fields, constant pools.
169 */
170 union VMJavaVal32 {
171 jint i;
172 jfloat f;
173 class oopDesc* r;
174 uint32_t raw;
175 };
177 /*
178 * Generic 64-bit Java value definition
179 */
180 union VMJavaVal64 {
181 jlong l;
182 jdouble d;
183 uint32_t v[2];
184 };
186 /*
187 * Generic 32-bit wide "Java slot" definition. This type occurs
188 * in Java locals, object fields, constant pools, and
189 * operand stacks (as a CVMStackVal32).
190 */
191 typedef union VMSlotVal32 {
192 VMJavaVal32 j; /* For "Java" values */
193 address a; /* a return created by jsr or jsr_w */
194 } VMSlotVal32;
197 /*
198 * Generic 32-bit wide stack slot definition.
199 */
200 union VMStackVal32 {
201 VMJavaVal32 j; /* For "Java" values */
202 VMSlotVal32 s; /* any value from a "slot" or locals[] */
203 };
205 inline JavaThread* thread() { return _thread; }
207 inline address bcp() { return _bcp; }
208 inline void set_bcp(address new_bcp) { _bcp = new_bcp; }
210 inline intptr_t* locals() { return _locals; }
212 inline ConstantPoolCache* constants() { return _constants; }
213 inline Method* method() { return _method; }
214 inline DataLayout* mdx() { return _mdx; }
215 inline void set_mdx(DataLayout *new_mdx) { _mdx = new_mdx; }
217 inline messages msg() { return _msg; }
218 inline void set_msg(messages new_msg) { _msg = new_msg; }
220 inline Method* callee() { return _result._to_call._callee; }
221 inline void set_callee(Method* new_callee) { _result._to_call._callee = new_callee; }
222 inline void set_callee_entry_point(address entry) { _result._to_call._callee_entry_point = entry; }
223 inline void set_osr_buf(address buf) { _result._osr._osr_buf = buf; }
224 inline void set_osr_entry(address entry) { _result._osr._osr_entry = entry; }
225 inline int bcp_advance() { return _result._to_call._bcp_advance; }
226 inline void set_bcp_advance(int count) { _result._to_call._bcp_advance = count; }
228 inline interpreterState prev() { return _prev_link; }
230 inline intptr_t* stack() { return _stack; }
231 inline void set_stack(intptr_t* new_stack) { _stack = new_stack; }
234 inline intptr_t* stack_base() { return _stack_base; }
235 inline intptr_t* stack_limit() { return _stack_limit; }
237 inline BasicObjectLock* monitor_base() { return _monitor_base; }
239 /*
240 * 64-bit Arithmetic:
241 *
242 * The functions below follow the semantics of the
243 * ladd, land, ldiv, lmul, lor, lxor, and lrem bytecodes,
244 * respectively.
245 */
247 static jlong VMlongAdd(jlong op1, jlong op2);
248 static jlong VMlongAnd(jlong op1, jlong op2);
249 static jlong VMlongDiv(jlong op1, jlong op2);
250 static jlong VMlongMul(jlong op1, jlong op2);
251 static jlong VMlongOr (jlong op1, jlong op2);
252 static jlong VMlongSub(jlong op1, jlong op2);
253 static jlong VMlongXor(jlong op1, jlong op2);
254 static jlong VMlongRem(jlong op1, jlong op2);
256 /*
257 * Shift:
258 *
259 * The functions below follow the semantics of the
260 * lushr, lshl, and lshr bytecodes, respectively.
261 */
263 static jlong VMlongUshr(jlong op1, jint op2);
264 static jlong VMlongShl (jlong op1, jint op2);
265 static jlong VMlongShr (jlong op1, jint op2);
267 /*
268 * Unary:
269 *
270 * Return the negation of "op" (-op), according to
271 * the semantics of the lneg bytecode.
272 */
274 static jlong VMlongNeg(jlong op);
276 /*
277 * Return the complement of "op" (~op)
278 */
280 static jlong VMlongNot(jlong op);
283 /*
284 * Comparisons to 0:
285 */
287 static int32_t VMlongLtz(jlong op); /* op <= 0 */
288 static int32_t VMlongGez(jlong op); /* op >= 0 */
289 static int32_t VMlongEqz(jlong op); /* op == 0 */
291 /*
292 * Between operands:
293 */
295 static int32_t VMlongEq(jlong op1, jlong op2); /* op1 == op2 */
296 static int32_t VMlongNe(jlong op1, jlong op2); /* op1 != op2 */
297 static int32_t VMlongGe(jlong op1, jlong op2); /* op1 >= op2 */
298 static int32_t VMlongLe(jlong op1, jlong op2); /* op1 <= op2 */
299 static int32_t VMlongLt(jlong op1, jlong op2); /* op1 < op2 */
300 static int32_t VMlongGt(jlong op1, jlong op2); /* op1 > op2 */
302 /*
303 * Comparisons (returning an jint value: 0, 1, or -1)
304 *
305 * Between operands:
306 *
307 * Compare "op1" and "op2" according to the semantics of the
308 * "lcmp" bytecode.
309 */
311 static int32_t VMlongCompare(jlong op1, jlong op2);
313 /*
314 * Convert int to long, according to "i2l" bytecode semantics
315 */
316 static jlong VMint2Long(jint val);
318 /*
319 * Convert long to int, according to "l2i" bytecode semantics
320 */
321 static jint VMlong2Int(jlong val);
323 /*
324 * Convert long to float, according to "l2f" bytecode semantics
325 */
326 static jfloat VMlong2Float(jlong val);
328 /*
329 * Convert long to double, according to "l2d" bytecode semantics
330 */
331 static jdouble VMlong2Double(jlong val);
333 /*
334 * Java floating-point float value manipulation.
335 *
336 * The result argument is, once again, an lvalue.
337 *
338 * Arithmetic:
339 *
340 * The functions below follow the semantics of the
341 * fadd, fsub, fmul, fdiv, and frem bytecodes,
342 * respectively.
343 */
345 static jfloat VMfloatAdd(jfloat op1, jfloat op2);
346 static jfloat VMfloatSub(jfloat op1, jfloat op2);
347 static jfloat VMfloatMul(jfloat op1, jfloat op2);
348 static jfloat VMfloatDiv(jfloat op1, jfloat op2);
349 static jfloat VMfloatRem(jfloat op1, jfloat op2);
351 /*
352 * Unary:
353 *
354 * Return the negation of "op" (-op), according to
355 * the semantics of the fneg bytecode.
356 */
358 static jfloat VMfloatNeg(jfloat op);
360 /*
361 * Comparisons (returning an int value: 0, 1, or -1)
362 *
363 * Between operands:
364 *
365 * Compare "op1" and "op2" according to the semantics of the
366 * "fcmpl" (direction is -1) or "fcmpg" (direction is 1) bytecodes.
367 */
369 static int32_t VMfloatCompare(jfloat op1, jfloat op2,
370 int32_t direction);
371 /*
372 * Conversion:
373 */
375 /*
376 * Convert float to double, according to "f2d" bytecode semantics
377 */
379 static jdouble VMfloat2Double(jfloat op);
381 /*
382 ******************************************
383 * Java double floating-point manipulation.
384 ******************************************
385 *
386 * The result argument is, once again, an lvalue.
387 *
388 * Conversions:
389 */
391 /*
392 * Convert double to int, according to "d2i" bytecode semantics
393 */
395 static jint VMdouble2Int(jdouble val);
397 /*
398 * Convert double to float, according to "d2f" bytecode semantics
399 */
401 static jfloat VMdouble2Float(jdouble val);
403 /*
404 * Convert int to double, according to "i2d" bytecode semantics
405 */
407 static jdouble VMint2Double(jint val);
409 /*
410 * Arithmetic:
411 *
412 * The functions below follow the semantics of the
413 * dadd, dsub, ddiv, dmul, and drem bytecodes, respectively.
414 */
416 static jdouble VMdoubleAdd(jdouble op1, jdouble op2);
417 static jdouble VMdoubleSub(jdouble op1, jdouble op2);
418 static jdouble VMdoubleDiv(jdouble op1, jdouble op2);
419 static jdouble VMdoubleMul(jdouble op1, jdouble op2);
420 static jdouble VMdoubleRem(jdouble op1, jdouble op2);
422 /*
423 * Unary:
424 *
425 * Return the negation of "op" (-op), according to
426 * the semantics of the dneg bytecode.
427 */
429 static jdouble VMdoubleNeg(jdouble op);
431 /*
432 * Comparisons (returning an int32_t value: 0, 1, or -1)
433 *
434 * Between operands:
435 *
436 * Compare "op1" and "op2" according to the semantics of the
437 * "dcmpl" (direction is -1) or "dcmpg" (direction is 1) bytecodes.
438 */
440 static int32_t VMdoubleCompare(jdouble op1, jdouble op2, int32_t direction);
442 /*
443 * Copy two typeless 32-bit words from one location to another.
444 * This is semantically equivalent to:
445 *
446 * to[0] = from[0];
447 * to[1] = from[1];
448 *
449 * but this interface is provided for those platforms that could
450 * optimize this into a single 64-bit transfer.
451 */
453 static void VMmemCopy64(uint32_t to[2], const uint32_t from[2]);
456 // Arithmetic operations
458 /*
459 * Java arithmetic methods.
460 * The functions below follow the semantics of the
461 * iadd, isub, imul, idiv, irem, iand, ior, ixor,
462 * and ineg bytecodes, respectively.
463 */
465 static jint VMintAdd(jint op1, jint op2);
466 static jint VMintSub(jint op1, jint op2);
467 static jint VMintMul(jint op1, jint op2);
468 static jint VMintDiv(jint op1, jint op2);
469 static jint VMintRem(jint op1, jint op2);
470 static jint VMintAnd(jint op1, jint op2);
471 static jint VMintOr (jint op1, jint op2);
472 static jint VMintXor(jint op1, jint op2);
474 /*
475 * Shift Operation:
476 * The functions below follow the semantics of the
477 * iushr, ishl, and ishr bytecodes, respectively.
478 */
480 static juint VMintUshr(jint op, jint num);
481 static jint VMintShl (jint op, jint num);
482 static jint VMintShr (jint op, jint num);
484 /*
485 * Unary Operation:
486 *
487 * Return the negation of "op" (-op), according to
488 * the semantics of the ineg bytecode.
489 */
491 static jint VMintNeg(jint op);
493 /*
494 * Int Conversions:
495 */
497 /*
498 * Convert int to float, according to "i2f" bytecode semantics
499 */
501 static jfloat VMint2Float(jint val);
503 /*
504 * Convert int to byte, according to "i2b" bytecode semantics
505 */
507 static jbyte VMint2Byte(jint val);
509 /*
510 * Convert int to char, according to "i2c" bytecode semantics
511 */
513 static jchar VMint2Char(jint val);
515 /*
516 * Convert int to short, according to "i2s" bytecode semantics
517 */
519 static jshort VMint2Short(jint val);
521 /*=========================================================================
522 * Bytecode interpreter operations
523 *=======================================================================*/
525 static void dup(intptr_t *tos);
526 static void dup2(intptr_t *tos);
527 static void dup_x1(intptr_t *tos); /* insert top word two down */
528 static void dup_x2(intptr_t *tos); /* insert top word three down */
529 static void dup2_x1(intptr_t *tos); /* insert top 2 slots three down */
530 static void dup2_x2(intptr_t *tos); /* insert top 2 slots four down */
531 static void swap(intptr_t *tos); /* swap top two elements */
533 // umm don't like this method modifies its object
535 // The Interpreter used when
536 static void run(interpreterState istate);
537 // The interpreter used if JVMTI needs interpreter events
538 static void runWithChecks(interpreterState istate);
539 static void End_Of_Interpreter(void);
541 // Inline static functions for Java Stack and Local manipulation
543 static address stack_slot(intptr_t *tos, int offset);
544 static jint stack_int(intptr_t *tos, int offset);
545 static jfloat stack_float(intptr_t *tos, int offset);
546 static oop stack_object(intptr_t *tos, int offset);
547 static jdouble stack_double(intptr_t *tos, int offset);
548 static jlong stack_long(intptr_t *tos, int offset);
550 // only used for value types
551 static void set_stack_slot(intptr_t *tos, address value, int offset);
552 static void set_stack_int(intptr_t *tos, int value, int offset);
553 static void set_stack_float(intptr_t *tos, jfloat value, int offset);
554 static void set_stack_object(intptr_t *tos, oop value, int offset);
556 // needs to be platform dep for the 32 bit platforms.
557 static void set_stack_double(intptr_t *tos, jdouble value, int offset);
558 static void set_stack_long(intptr_t *tos, jlong value, int offset);
560 static void set_stack_double_from_addr(intptr_t *tos, address addr, int offset);
561 static void set_stack_long_from_addr(intptr_t *tos, address addr, int offset);
563 // Locals
565 static address locals_slot(intptr_t* locals, int offset);
566 static jint locals_int(intptr_t* locals, int offset);
567 static jfloat locals_float(intptr_t* locals, int offset);
568 static oop locals_object(intptr_t* locals, int offset);
569 static jdouble locals_double(intptr_t* locals, int offset);
570 static jlong locals_long(intptr_t* locals, int offset);
572 static address locals_long_at(intptr_t* locals, int offset);
573 static address locals_double_at(intptr_t* locals, int offset);
575 static void set_locals_slot(intptr_t *locals, address value, int offset);
576 static void set_locals_int(intptr_t *locals, jint value, int offset);
577 static void set_locals_float(intptr_t *locals, jfloat value, int offset);
578 static void set_locals_object(intptr_t *locals, oop value, int offset);
579 static void set_locals_double(intptr_t *locals, jdouble value, int offset);
580 static void set_locals_long(intptr_t *locals, jlong value, int offset);
581 static void set_locals_double_from_addr(intptr_t *locals,
582 address addr, int offset);
583 static void set_locals_long_from_addr(intptr_t *locals,
584 address addr, int offset);
586 static void astore(intptr_t* topOfStack, int stack_offset,
587 intptr_t* locals, int locals_offset);
589 // Support for dup and swap
590 static void copy_stack_slot(intptr_t *tos, int from_offset, int to_offset);
592 #ifndef PRODUCT
593 static const char* C_msg(BytecodeInterpreter::messages msg);
594 void print();
595 #endif // PRODUCT
597 // Platform fields/methods
598 #ifdef TARGET_ARCH_x86
599 # include "bytecodeInterpreter_x86.hpp"
600 #endif
601 #ifdef TARGET_ARCH_mips
602 # include "bytecodeInterpreter_mips.hpp"
603 #endif
604 #ifdef TARGET_ARCH_sparc
605 # include "bytecodeInterpreter_sparc.hpp"
606 #endif
607 #ifdef TARGET_ARCH_zero
608 # include "bytecodeInterpreter_zero.hpp"
609 #endif
610 #ifdef TARGET_ARCH_arm
611 # include "bytecodeInterpreter_arm.hpp"
612 #endif
613 #ifdef TARGET_ARCH_ppc
614 # include "bytecodeInterpreter_ppc.hpp"
615 #endif
618 }; // BytecodeInterpreter
620 #endif // CC_INTERP
622 #endif // SHARE_VM_INTERPRETER_BYTECODEINTERPRETER_HPP