Skip to content
Permalink
Browse files
8263776: [JVMCI] add helper to perform Java upcalls
Reviewed-by: kvn
  • Loading branch information
Tom Rodriguez committed Mar 23, 2021
1 parent b23228d commit 6b4c654186e49528eeae7249fdcd0f2d1a98b3ad
Showing with 114 additions and 0 deletions.
  1. +107 −0 src/hotspot/share/jvmci/jvmciRuntime.cpp
  2. +5 −0 src/hotspot/share/jvmci/jvmciRuntime.hpp
  3. +2 −0 src/hotspot/share/jvmci/vmStructs_jvmci.cpp
@@ -456,6 +456,113 @@ JRT_BLOCK_ENTRY(int, JVMCIRuntime::throw_class_cast_exception(JavaThread* thread
return caller_is_deopted();
JRT_END

class ArgumentPusher : public SignatureIterator {
protected:
JavaCallArguments* _jca;
jlong _argument;
bool _pushed;

jlong next_arg() {
guarantee(!_pushed, "one argument");
_pushed = true;
return _argument;
}

float next_float() {
guarantee(!_pushed, "one argument");
_pushed = true;
jvalue v;
v.i = (jint) _argument;
return v.f;
}

double next_double() {
guarantee(!_pushed, "one argument");
_pushed = true;
jvalue v;
v.j = _argument;
return v.d;
}

Handle next_object() {
guarantee(!_pushed, "one argument");
_pushed = true;
return Handle(Thread::current(), (oop) (address) _argument);
}

public:
ArgumentPusher(Symbol* signature, JavaCallArguments* jca, jlong argument) : SignatureIterator(signature) {
this->_return_type = T_ILLEGAL;
_jca = jca;
_argument = argument;
_pushed = false;
do_parameters_on(this);
}

void do_type(BasicType type) {
switch (type) {
case T_OBJECT:
case T_ARRAY: _jca->push_oop(next_object()); break;
case T_BOOLEAN: _jca->push_int((jboolean) next_arg()); break;
case T_CHAR: _jca->push_int((jchar) next_arg()); break;
case T_SHORT: _jca->push_int((jint) next_arg()); break;
case T_BYTE: _jca->push_int((jbyte) next_arg()); break;
case T_INT: _jca->push_int((jint) next_arg()); break;
case T_LONG: _jca->push_long((jlong) next_arg()); break;
case T_FLOAT: _jca->push_float(next_float()); break;
case T_DOUBLE: _jca->push_double(next_double()); break;
default: fatal("Unexpected type %s", type2name(type));
}
}
};


JRT_ENTRY(jlong, JVMCIRuntime::invoke_static_method_one_arg(JavaThread* thread, Method* method, jlong argument))
ResourceMark rm;
HandleMark hm(THREAD);

methodHandle mh(thread, method);
if (mh->size_of_parameters() > 1 && !mh->is_static()) {
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Invoked method must be static and take at most one argument");
}

Symbol* signature = mh->signature();
JavaCallArguments jca(mh->size_of_parameters());
ArgumentPusher jap(signature, &jca, argument);
BasicType return_type = jap.return_type();
JavaValue result(return_type);
JavaCalls::call(&result, mh, &jca, CHECK_0);

if (return_type == T_VOID) {
return 0;
} else if (return_type == T_OBJECT || return_type == T_ARRAY) {
thread->set_vm_result((oop) result.get_jobject());
return 0;
} else {
jvalue *value = (jvalue *) result.get_value_addr();
// Narrow the value down if required (Important on big endian machines)
switch (return_type) {
case T_BOOLEAN:
return (jboolean) value->i;
case T_BYTE:
return (jbyte) value->i;
case T_CHAR:
return (jchar) value->i;
case T_SHORT:
return (jshort) value->i;
case T_INT:
case T_FLOAT:
return value->i;
case T_LONG:
case T_DOUBLE:
return value->j;
default:
fatal("Unexpected type %s", type2name(return_type));
return 0;
}
}
JRT_END

JRT_LEAF(void, JVMCIRuntime::log_object(JavaThread* thread, oopDesc* obj, bool as_string, bool newline))
ttyLocker ttyl;

@@ -412,6 +412,11 @@ class JVMCIRuntime: public CHeapObj<mtJVMCI> {
static int throw_klass_external_name_exception(JavaThread* thread, const char* exception, Klass* klass);
static int throw_class_cast_exception(JavaThread* thread, const char* exception, Klass* caster_klass, Klass* target_klass);

// A helper to allow invocation of an arbitrary Java method. For simplicity the method is
// restricted to a static method that takes at most one argument. For calling convention
// simplicty all types are passed by being converted into a jlong
static jlong invoke_static_method_one_arg(JavaThread* thread, Method* method, jlong argument);

// Test only function
static jint test_deoptimize_call_int(JavaThread* thread, int value);
};
@@ -684,6 +684,8 @@
declare_function(JVMCIRuntime::dynamic_new_array_or_null) \
declare_function(JVMCIRuntime::dynamic_new_instance_or_null) \
\
declare_function(JVMCIRuntime::invoke_static_method_one_arg) \
\
declare_function(JVMCIRuntime::vm_message) \
declare_function(JVMCIRuntime::identity_hash_code) \
declare_function(JVMCIRuntime::exception_handler_for_pc) \

3 comments on commit 6b4c654

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot replied Mar 23, 2021

@jerboaa

This comment has been minimized.

Copy link
Contributor

@jerboaa jerboaa replied Aug 20, 2021

/backport jdk11u-dev

@openjdk

This comment has been minimized.

Copy link

@openjdk openjdk bot replied Aug 20, 2021

@jerboaa could not automatically backport 6b4c6541 to openjdk/jdk11u-dev due to conflicts in the following files:

  • src/hotspot/share/jvmci/vmStructs_jvmci.cpp

To manually resolve these conflicts run the following commands in your personal fork of openjdk/jdk11u-dev:

$ git checkout -b jerboaa-backport-6b4c6541
$ git fetch --no-tags https://git.openjdk.java.net/jdk 6b4c654186e49528eeae7249fdcd0f2d1a98b3ad
$ git cherry-pick --no-commit 6b4c654186e49528eeae7249fdcd0f2d1a98b3ad
$ # Resolve conflicts
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 6b4c654186e49528eeae7249fdcd0f2d1a98b3ad'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport 6b4c654186e49528eeae7249fdcd0f2d1a98b3ad.

Please sign in to comment.