--- old/src/hotspot/share/runtime/javaCalls.cpp 2019-07-02 16:16:45.000000000 +0200 +++ new/src/hotspot/share/runtime/javaCalls.cpp 2019-07-02 16:16:41.000000000 +0200 @@ -411,7 +411,7 @@ BasicType result_type = runtime_type_from(result); bool oop_result_flag = (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY || result->get_type() == T_VALUETYPE); - + // NOTE: if we move the computation of the result_val_address inside // the call to call_stub, the optimizer produces wrong code. intptr_t* result_val_address = (intptr_t*)(result->get_value_addr()); @@ -449,11 +449,23 @@ } #endif + Handle vt; + if (ValueTypeReturnedAsFields && result->get_type() == T_VALUETYPE) { + // Pre allocate buffered value in case the result is returned + // flattened by compiled code + ValueKlass* vk = method->returned_value_type(thread); + vt = vk->allocate_instance_handle(CHECK); + } + // do call { JavaCallWrapper link(method, receiver, result, CHECK); { HandleMark hm(thread); // HandleMark used by HandleMarkCleaner - StubRoutines::call_stub()( + if (vt() != NULL) { + result->set_jobject((jobject)vt()); + } + + StubRoutines::call_stub()( (address)&link, // (intptr_t*)&(result->_value), // see NOTE above (compiler problem) result_val_address, // see NOTE above (compiler problem)