/* * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
InterpreterCodelet* ZeroInterpreter::codelet_containing(address pc) { // FIXME: I'm pretty sure _code is null and this is never called, which is why it's copied. return (InterpreterCodelet*)_code->stub_containing(pc);
} #define fixup_after_potential_safepoint() \
method = istate->method()
// Shortcut if reference is known NULL if (ref == NULL) { return normal_entry(method, 0, THREAD);
}
// Read the referent with weaker semantics, and let GCs handle the rest. constint referent_offset = java_lang_ref_Reference::referent_offset();
oop obj = HeapAccess<IN_HEAP | ON_WEAK_OOP_REF>::oop_load_at(ref, referent_offset);
SET_STACK_OBJECT(obj, 0);
// No deoptimized frames on the stack return 0;
}
intptr_t narrow(BasicType type, intptr_t result) { // mask integer result to narrower return type. switch (type) { case T_BOOLEAN: return result&1; case T_BYTE: return (intptr_t)(jbyte)result; case T_CHAR: return (intptr_t)(uintptr_t)(jchar)result; case T_SHORT: return (intptr_t)(jshort)result; case T_OBJECT: // nothing to do fall through case T_ARRAY: case T_LONG: case T_INT: case T_FLOAT: case T_DOUBLE: case T_VOID: return result; default:
ShouldNotReachHere(); return result; // silence compiler warnings
}
}
// If we are entering from a deopt we may need to call // ourself a few times in order to get to our frame. if (recurse)
main_loop(recurse - 1, THREAD);
while (true) { // We can set up the frame anchor with everything we want at // this point as we are thread_in_Java and no safepoints can // occur until we go to vm mode. We do have to clear flags // on return from vm but that is it.
thread->set_last_Java_frame();
// Call the interpreter if (JvmtiExport::can_post_interpreter_events()) { if (RewriteBytecodes) {
BytecodeInterpreter::run<true, true>(istate);
} else {
BytecodeInterpreter::run<true, false>(istate);
}
} else { if (RewriteBytecodes) {
BytecodeInterpreter::run<false, true>(istate);
} else {
BytecodeInterpreter::run<false, false>(istate);
}
}
fixup_after_potential_safepoint();
// If we are unwinding, notify the stack watermarks machinery. // Should do this before resetting the frame anchor. if (istate->msg() == BytecodeInterpreter::return_from_method ||
istate->msg() == BytecodeInterpreter::do_osr) {
stack_watermark_unwind_check(thread);
} else {
assert(istate->msg() == BytecodeInterpreter::call_method ||
istate->msg() == BytecodeInterpreter::more_monitors ||
istate->msg() == BytecodeInterpreter::throwing_exception, "Should be one of these otherwise");
}
// Clear the frame anchor
thread->reset_last_Java_frame();
// Examine the message from the interpreter to decide what to do if (istate->msg() == BytecodeInterpreter::call_method) {
Method* callee = istate->callee();
// Trim back the stack to put the parameters at the top
stack->set_sp(istate->stack() + 1);
// Make the call
Interpreter::invoke_method(callee, istate->callee_entry_point(), THREAD);
fixup_after_potential_safepoint();
// Convert the result
istate->set_stack(stack->sp() - 1);
// Restore the stack
stack->set_sp(istate->stack_limit() + 1);
// Resume the interpreter
istate->set_msg(BytecodeInterpreter::method_resume);
} elseif (istate->msg() == BytecodeInterpreter::more_monitors) { int monitor_words = frame::interpreter_frame_monitor_size();
// Allocate the space
stack->overflow_check(monitor_words, THREAD); if (HAS_PENDING_EXCEPTION) break;
stack->alloc(monitor_words * wordSize);
// Move the expression stack contents for (intptr_t *p = istate->stack() + 1; p < istate->stack_base(); p++)
*(p - monitor_words) = *p;
// Zero the new monitor so the interpreter can find it.
((BasicObjectLock *) istate->stack_base())->set_obj(NULL);
// Resume the interpreter
istate->set_msg(BytecodeInterpreter::got_monitors);
} elseif (istate->msg() == BytecodeInterpreter::return_from_method) { // Copy the result into the caller's frame
result_slots = type2size[method->result_type()];
assert(result_slots >= 0 && result_slots <= 2, "what?");
result = istate->stack() + result_slots; break;
} elseif (istate->msg() == BytecodeInterpreter::throwing_exception) {
assert(HAS_PENDING_EXCEPTION, "should do"); break;
} elseif (istate->msg() == BytecodeInterpreter::do_osr) { // Unwind the current frame
thread->pop_zero_frame();
// Remove any extension of the previous frame int extra_locals = method->max_locals() - method->size_of_parameters();
stack->set_sp(stack->sp() + extra_locals);
// Jump into the OSR method
Interpreter::invoke_osr(
method, istate->osr_entry(), istate->osr_buf(), THREAD); return;
} else {
ShouldNotReachHere();
}
}
// Unwind the current frame
thread->pop_zero_frame();
// Pop our local variables
stack->set_sp(stack->sp() + method->max_locals());
// Push our result for (int i = 0; i < result_slots; i++) { // Adjust result to smaller union {
intptr_t res;
jint res_jint;
};
res = result[-i]; if (result_slots == 1) {
BasicType t = method->result_type(); if (is_subword_type(t)) {
res_jint = (jint)narrow(t, res_jint);
}
}
stack->push(res);
}
}
int ZeroInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) { // Make sure method is native and not abstract
assert(method->is_native() && !method->is_abstract(), "should be");
// Get the native function entry point
address function;
function = method->native_function();
assert(function != NULL, "should be set if signature handler is");
// Build the argument list
stack->overflow_check(handler->argument_count() * 2, THREAD); if (HAS_PENDING_EXCEPTION) goto unlock_unwind_and_return;
// Set up the Java frame anchor
thread->set_last_Java_frame();
// Change the thread state to _thread_in_native
ThreadStateTransition::transition_from_java(thread, _thread_in_native);
// Make the call
intptr_t result[4 - LogBytesPerWord];
ffi_call(handler->cif(), (void (*)()) function, result, arguments);
// Change the thread state back to _thread_in_Java and ensure it // is seen by the GC thread. // ThreadStateTransition::transition_from_native() cannot be used // here because it does not check for asynchronous exceptions. // We have to manage the transition ourself.
thread->set_thread_state_fence(_thread_in_native_trans);
// Handle safepoint operations, pending suspend requests, // and pending asynchronous exceptions. if (SafepointMechanism::should_process(thread) ||
thread->has_special_condition_for_native_trans()) {
JavaThread::check_special_condition_for_native_trans(thread);
CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops());
}
// Finally we can change the thread state to _thread_in_Java.
thread->set_thread_state(_thread_in_Java);
fixup_after_potential_safepoint();
// Notify the stack watermarks machinery that we are unwinding. // Should do this before resetting the frame anchor.
stack_watermark_unwind_check(thread);
// Clear the frame anchor
thread->reset_last_Java_frame();
// If the result was an oop then unbox it and store it in // oop_temp where the garbage collector can see it before // we release the handle it might be protected by. if (handler->result_type() == &ffi_type_pointer) { if (result[0] == 0) {
istate->set_oop_temp(NULL);
} else {
jobject handle = reinterpret_cast<jobject>(result[0]);
istate->set_oop_temp(JNIHandles::resolve(handle));
}
}
case T_LONG:
SET_LOCALS_LONG(*(jlong *) result, 0); break;
case T_FLOAT:
SET_LOCALS_FLOAT(*(jfloat *) result, 0); break;
case T_DOUBLE:
SET_LOCALS_DOUBLE(*(jdouble *) result, 0); break;
case T_OBJECT: case T_ARRAY:
SET_LOCALS_OBJECT(istate->oop_temp(), 0); break;
default:
ShouldNotReachHere();
}
}
// Already did every pending exception check here. // If HAS_PENDING_EXCEPTION is true, the interpreter would handle the rest. if (CheckJNICalls) {
THREAD->clear_pending_jni_exception_check();
}
// No deoptimized frames on the stack return 0;
}
int ZeroInterpreter::getter_entry(Method* method, intptr_t UNUSED, TRAPS) {
JavaThread* thread = THREAD; // Drop into the slow path if we need a safepoint check if (SafepointMechanism::should_process(thread)) { return normal_entry(method, 0, THREAD);
}
// Read the field index from the bytecode: // 0: aload_0 // 1: getfield // 2: index // 3: index // 4: return // // NB this is not raw bytecode: index is in machine order
assert(method->is_getter(), "Expect the particular bytecode shape");
u1* code = method->code_base();
u2 index = Bytes::get_native_u2(&code[2]);
// Get the entry from the constant pool cache, and drop into // the slow path if it has not been resolved
ConstantPoolCache* cache = method->constants()->cache();
ConstantPoolCacheEntry* entry = cache->entry_at(index); if (!entry->is_resolved(Bytecodes::_getfield)) { return normal_entry(method, 0, THREAD);
}
// Load the object pointer and drop into the slow path // if we have a NullPointerException
oop object = STACK_OBJECT(0); if (object == NULL) { return normal_entry(method, 0, THREAD);
}
// If needed, allocate additional slot on stack: we already have one // for receiver, and double/long need another one. switch (entry->flag_state()) { case ltos: case dtos:
stack->overflow_check(1, CHECK_0);
stack->alloc(wordSize);
topOfStack = stack->sp(); break; default:
;
}
// Read the field to stack(0) int offset = entry->f2_as_index(); if (entry->is_volatile()) { if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
OrderAccess::fence();
} switch (entry->flag_state()) { case btos: case ztos: SET_STACK_INT(object->byte_field_acquire(offset), 0); break; case ctos: SET_STACK_INT(object->char_field_acquire(offset), 0); break; case stos: SET_STACK_INT(object->short_field_acquire(offset), 0); break; case itos: SET_STACK_INT(object->int_field_acquire(offset), 0); break; case ltos: SET_STACK_LONG(object->long_field_acquire(offset), 0); break; case ftos: SET_STACK_FLOAT(object->float_field_acquire(offset), 0); break; case dtos: SET_STACK_DOUBLE(object->double_field_acquire(offset), 0); break; case atos: SET_STACK_OBJECT(object->obj_field_acquire(offset), 0); break; default:
ShouldNotReachHere();
}
} else { switch (entry->flag_state()) { case btos: case ztos: SET_STACK_INT(object->byte_field(offset), 0); break; case ctos: SET_STACK_INT(object->char_field(offset), 0); break; case stos: SET_STACK_INT(object->short_field(offset), 0); break; case itos: SET_STACK_INT(object->int_field(offset), 0); break; case ltos: SET_STACK_LONG(object->long_field(offset), 0); break; case ftos: SET_STACK_FLOAT(object->float_field(offset), 0); break; case dtos: SET_STACK_DOUBLE(object->double_field(offset), 0); break; case atos: SET_STACK_OBJECT(object->obj_field(offset), 0); break; default:
ShouldNotReachHere();
}
}
// No deoptimized frames on the stack return 0;
}
int ZeroInterpreter::setter_entry(Method* method, intptr_t UNUSED, TRAPS) {
JavaThread* thread = THREAD; // Drop into the slow path if we need a safepoint check if (SafepointMechanism::should_process(thread)) { return normal_entry(method, 0, THREAD);
}
// Read the field index from the bytecode: // 0: aload_0 // 1: *load_1 // 2: putfield // 3: index // 4: index // 5: return // // NB this is not raw bytecode: index is in machine order
assert(method->is_setter(), "Expect the particular bytecode shape");
u1* code = method->code_base();
u2 index = Bytes::get_native_u2(&code[3]);
// Get the entry from the constant pool cache, and drop into // the slow path if it has not been resolved
ConstantPoolCache* cache = method->constants()->cache();
ConstantPoolCacheEntry* entry = cache->entry_at(index); if (!entry->is_resolved(Bytecodes::_putfield)) { return normal_entry(method, 0, THREAD);
}
// Figure out where the receiver is. If there is a long/double // operand on stack top, then receiver is two slots down.
oop object = NULL; switch (entry->flag_state()) { case ltos: case dtos:
object = STACK_OBJECT(-2); break; default:
object = STACK_OBJECT(-1); break;
}
// Load the receiver pointer and drop into the slow path // if we have a NullPointerException if (object == NULL) { return normal_entry(method, 0, THREAD);
}
// Store the stack(0) to field int offset = entry->f2_as_index(); if (entry->is_volatile()) { switch (entry->flag_state()) { case btos: object->release_byte_field_put(offset, STACK_INT(0)); break; case ztos: object->release_byte_field_put(offset, STACK_INT(0) & 1); break; // only store LSB case ctos: object->release_char_field_put(offset, STACK_INT(0)); break; case stos: object->release_short_field_put(offset, STACK_INT(0)); break; case itos: object->release_int_field_put(offset, STACK_INT(0)); break; case ltos: object->release_long_field_put(offset, STACK_LONG(0)); break; case ftos: object->release_float_field_put(offset, STACK_FLOAT(0)); break; case dtos: object->release_double_field_put(offset, STACK_DOUBLE(0)); break; case atos: object->release_obj_field_put(offset, STACK_OBJECT(0)); break; default:
ShouldNotReachHere();
}
OrderAccess::storeload();
} else { switch (entry->flag_state()) { case btos: object->byte_field_put(offset, STACK_INT(0)); break; case ztos: object->byte_field_put(offset, STACK_INT(0) & 1); break; // only store LSB case ctos: object->char_field_put(offset, STACK_INT(0)); break; case stos: object->short_field_put(offset, STACK_INT(0)); break; case itos: object->int_field_put(offset, STACK_INT(0)); break; case ltos: object->long_field_put(offset, STACK_LONG(0)); break; case ftos: object->float_field_put(offset, STACK_FLOAT(0)); break; case dtos: object->double_field_put(offset, STACK_DOUBLE(0)); break; case atos: object->obj_field_put(offset, STACK_OBJECT(0)); break; default:
ShouldNotReachHere();
}
}
// Nothing is returned, pop out parameters
stack->set_sp(stack->sp() + method->size_of_parameters());
// Calculate the size of the frame we'll build, including // any adjustments to the caller's frame that we'll make. int extra_locals = 0; int monitor_words = 0; int stack_words = 0;
// Adjust the caller's stack frame to accommodate any additional // local variables we have contiguously with our parameters. for (int i = 0; i < extra_locals; i++)
stack->push(0);
address ZeroInterpreter::deopt_entry(TosState state, int length) { return NULL;
}
address ZeroInterpreter::remove_activation_preserving_args_entry() { // Do an uncommon trap type entry. c++ interpreter will know // to pop frame and preserve the args return Interpreter::deopt_entry(vtos, 0);
}
// Helper for figuring out if frames are interpreter frames
bool ZeroInterpreter::contains(address pc) { returnfalse; // make frame::print_value_on work
}
void ZeroInterpreter::stack_watermark_unwind_check(JavaThread* thread) { // If frame pointer is in the danger zone, notify the runtime that // it needs to act before continuing the unwinding.
uintptr_t fp = (uintptr_t)thread->last_Java_fp();
uintptr_t watermark = thread->poll_data()->get_polling_word(); if (fp > watermark) {
InterpreterRuntime::at_unwind(thread);
}
}
¤ Dauer der Verarbeitung: 0.3 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.