/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*
*/
#include "precompiled.hpp"
#include "classfile/systemDictionary.hpp"
#include "classfile/vmSymbols.hpp"
#include "code/nmethod.hpp"
#include "compiler/compileBroker.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/linkResolver.hpp"
#include "memory/universe.inline.hpp"
#include "oops/oop.inline.hpp"
#include "prims/jniCheck.hpp"
#include "runtime/compilationPolicy.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/interfaceSupport.hpp"
#include "runtime/javaCalls.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/signature.hpp"
#include "runtime/stubRoutines.hpp"
#ifdef TARGET_OS_FAMILY_linux
# include "thread_linux.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_solaris
# include "thread_solaris.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_windows
# include "thread_windows.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_bsd
# include "thread_bsd.inline.hpp"
#endif
// -----------------------------------------------------
// Implementation of JavaCallWrapper
JavaCallWrapper::JavaCallWrapper(methodHandle callee_method, Handle receiver, JavaValue* result, TRAPS) {
bool clear_pending_exception = true;
guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
// Allocate handle block for Java code. This must be done before we change thread_state to _thread_in_Java_or_stub,
// since it can potentially block.
// After this, we are official in JavaCode. This needs to be done before we change any of the thread local
// info, since we cannot find oops before the new information is set up completely.
// Make sure that we handle asynchronous stops and suspends _before_ we clear all thread state
// in JavaCallWrapper::JavaCallWrapper(). This way, we can decide if we need to do any pd actions
if (thread->has_special_runtime_exit_condition()) {
if (HAS_PENDING_EXCEPTION) {
clear_pending_exception = false;
}
}
// Make sure to set the oop's after the thread transition - since we can block there. No one is GC'ing
// the JavaCallWrapper before the entry frame is on the stack.
#ifdef CHECK_UNHANDLED_OOPS
#endif // CHECK_UNHANDLED_OOPS
// For the profiler, the last_Java_frame information in thread must always be in
// legal state. We have no last Java frame if last_Java_sp == NULL so
// the valid transition is to clear _last_Java_sp and then reset the rest of
// the (platform specific) state.
// clear any pending exception in thread (native calls start with no exception pending)
if(clear_pending_exception) {
}
}
}
// restore previous handle block & Java frame linkage
}
// Old thread-local info. has been restored. We are not back in the VM.
// State has been restored now make the anchor frame visible for the profiler.
// Do this after the transition because this allows us to put an assert
// the Java->vm transition which checks to see that stack is not walkable
// invariants (i.e. _flags always cleared on return to Java)
// Release handles after we are marked as being inside the VM again, since this
// operation might block
}
}
// Helper methods
case T_BOOLEAN: // fall through
case T_CHAR : // fall through
case T_SHORT : // fall through
case T_INT : // fall through
#ifndef _LP64
case T_OBJECT : // fall through
case T_ARRAY : // fall through
#endif
case T_BYTE : // fall through
#ifdef _LP64
case T_ARRAY : // fall through
#endif
}
return T_ILLEGAL;
}
// ===== object constructor calls =====
void JavaCalls::call_default_constructor(JavaThread* thread, methodHandle method, Handle receiver, TRAPS) {
assert(method->name() == vmSymbols::object_initializer_name(), "Should only be called for default constructor");
assert(method->signature() == vmSymbols::void_method_signature(), "Should only be called for default constructor");
// safe to skip constructor call
} else {
}
}
// ============ Virtual calls ============
void JavaCalls::call_virtual(JavaValue* result, KlassHandle spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
KlassHandle(), false, true, CHECK);
// Invoke the method
}
void JavaCalls::call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, TRAPS) {
}
void JavaCalls::call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
}
void JavaCalls::call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
}
// ============ Special calls ============
void JavaCalls::call_special(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
// Invoke the method
}
void JavaCalls::call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
}
void JavaCalls::call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
}
void JavaCalls::call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
}
// ============ Static calls ============
void JavaCalls::call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
LinkResolver::resolve_static_call(callinfo, klass, name, signature, KlassHandle(), false, true, CHECK);
// Invoke the method
}
void JavaCalls::call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
}
void JavaCalls::call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS) {
}
void JavaCalls::call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS) {
}
// -------------------------------------------------
// Implementation of JavaCalls (low level)
// Check if we need to wrap a potential OS exception handler around thread
// This is used for e.g. Win32 structured exception handlers
// Need to wrap each and everytime, since there might be native code down the
// stack that has installed its own exception handlers
}
// Verify the arguments
if (CheckJNICalls) {
}
// Ignore call if method is empty
if (method->is_empty_method()) {
return;
}
#ifdef ASSERT
// A klass might not be initialized since JavaCall's might be used during the executing of
// the <clinit>. For example, a Thread.start might start executing on an object that is
// not fully initialized! (bad Java programming style)
}
#endif
}
// Since the call stub sets up like the interpreter we call the from_interpreted_entry
// so we can go compiled via a i2c. Otherwise initial entry method will always
// run interpreted.
}
// Figure out if the result value is an oop or not (Note: This is a different value
// than result_type. result_type will be T_INT of oops. (it is about size)
// NOTE: if we move the computation of the result_val_address inside
// the call to call_stub, the optimizer produces wrong code.
// Find receiver
// When we reenter Java, we need to reenable the yellow zone which
// might already be disabled when we are in VM.
if (thread->stack_yellow_zone_disabled()) {
thread->reguard_stack();
}
// Check that there are shadow pages available before changing thread state
// to Java
// Throw stack overflow exception with preinitialized exception.
return;
} else {
// Touch pages checked if the OS needs them to be touched to be mapped.
}
// do call
// (intptr_t*)&(result->_value), // see NOTE above (compiler problem)
result_val_address, // see NOTE above (compiler problem)
method(),
args->parameters(),
);
// Preserve oop return value across possible gc points
if (oop_result_flag) {
}
}
} // Exit JavaCallWrapper (can block - potential return oop must be preserved)
// Check if a thread stop or suspend should be executed
// The following assert was not realistic. Thread.stop can set that bit at any moment.
//assert(!thread->has_special_runtime_exit_condition(), "no async. exceptions should be installed");
// Restore possible oop return
if (oop_result_flag) {
}
}
//--------------------------------------------------------------------------------------
// Implementation of JavaCallArguments
// First convert all handles to oops
for(int i = 0; i < _size; i++) {
if (_is_oop[i]) {
// Handle conversion
}
}
// Return argument vector
return _value;
}
private:
bool *_is_oop;
int _pos;
public:
bool _is_return;
SignatureChekker(Symbol* signature, BasicType return_type, bool is_static, bool* is_oop, intptr_t* value, Thread* thread) : SignatureIterator(signature) {
_is_return = false;
_pos = 0;
if (!is_static) {
check_value(true); // Receiver must be an oop
}
}
}
}
if (_is_return) {
return;
}
check_value(false);
}
if (_is_return) {
return;
}
check_value(false);
check_value(false);
}
if (_is_return) {
return;
}
// verify handle and the oop pointed to by handle
int p = _pos;
bool bad = false;
// If argument is oop
if (_is_oop[p]) {
if (v != 0 ) {
if (CheckJNICalls && bad) {
}
}
// for the regular debug case.
}
check_value(true);
}
};
// Treat T_OBJECT and T_ARRAY as the same
// Check that oop information is correct
sc.check_doing_return(true);
}