mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-04 07:28:22 +00:00
8149159: Clean up Unsafe
Reviewed-by: jrose, kvn, stsmirno, chegar, aph, psandoz, redestad, twisti
This commit is contained in:
parent
adde13cc80
commit
c40e7bc21f
@ -1035,14 +1035,13 @@
|
||||
do_name( updateByteBuffer_A_name, "updateByteBuffer") \
|
||||
\
|
||||
/* support for Unsafe */ \
|
||||
do_class(sun_misc_Unsafe, "sun/misc/Unsafe") \
|
||||
do_class(jdk_internal_misc_Unsafe, "jdk/internal/misc/Unsafe") \
|
||||
\
|
||||
do_intrinsic(_allocateInstance, jdk_internal_misc_Unsafe, allocateInstance_name, allocateInstance_signature, F_RN) \
|
||||
do_name( allocateInstance_name, "allocateInstance") \
|
||||
do_signature(allocateInstance_signature, "(Ljava/lang/Class;)Ljava/lang/Object;") \
|
||||
do_intrinsic(_copyMemory, jdk_internal_misc_Unsafe, copyMemory_name, copyMemory_signature, F_RN) \
|
||||
do_name( copyMemory_name, "copyMemory") \
|
||||
do_name( copyMemory_name, "copyMemory0") \
|
||||
do_signature(copyMemory_signature, "(Ljava/lang/Object;JLjava/lang/Object;JJ)V") \
|
||||
do_intrinsic(_loadFence, jdk_internal_misc_Unsafe, loadFence_name, loadFence_signature, F_RN) \
|
||||
do_name( loadFence_name, "loadFence") \
|
||||
|
||||
@ -1338,73 +1338,6 @@ vmSymbols::SID Method::klass_id_for_intrinsics(const Klass* holder) {
|
||||
return vmSymbols::find_sid(klass_name);
|
||||
}
|
||||
|
||||
static bool is_unsafe_alias(vmSymbols::SID name_id) {
|
||||
// All 70 intrinsic candidate methods from sun.misc.Unsafe in 1.8.
|
||||
// Some have the same method name but different signature, e.g.
|
||||
// getByte(long), getByte(Object,long)
|
||||
switch (name_id) {
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(allocateInstance_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(copyMemory_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(loadFence_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(storeFence_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(fullFence_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getObject_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getBoolean_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getByte_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getShort_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getChar_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getInt_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getLong_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getFloat_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getDouble_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putObject_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putBoolean_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putByte_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putShort_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putChar_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putInt_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putLong_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putFloat_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putDouble_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getObjectVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getBooleanVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getByteVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getShortVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getCharVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getIntVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getLongVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getFloatVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getDoubleVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putObjectVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putBooleanVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putByteVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putShortVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putCharVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putIntVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putLongVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putFloatVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putDoubleVolatile_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getAddress_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putAddress_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(compareAndSwapObject_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(compareAndSwapLong_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(compareAndSwapInt_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putOrderedObject_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putOrderedLong_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(putOrderedInt_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getAndAddInt_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getAndAddLong_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getAndSetInt_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getAndSetLong_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(getAndSetObject_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(park_name):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(unpark_name):
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Method::init_intrinsic_id() {
|
||||
assert(_intrinsic_id == vmIntrinsics::_none, "do this just once");
|
||||
const uintptr_t max_id_uint = right_n_bits((int)(sizeof(_intrinsic_id) * BitsPerByte));
|
||||
@ -1457,14 +1390,6 @@ void Method::init_intrinsic_id() {
|
||||
if (is_static() != MethodHandles::is_signature_polymorphic_static(id))
|
||||
id = vmIntrinsics::_none;
|
||||
break;
|
||||
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(sun_misc_Unsafe):
|
||||
// Map sun.misc.Unsafe to jdk.internal.misc.Unsafe
|
||||
if (!is_unsafe_alias(name_id)) break;
|
||||
// pretend it is the corresponding method in the internal Unsafe class:
|
||||
klass_id = vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_misc_Unsafe);
|
||||
id = vmIntrinsics::find_id(klass_id, name_id, sig_id, flags);
|
||||
break;
|
||||
}
|
||||
|
||||
if (id != vmIntrinsics::_none) {
|
||||
|
||||
@ -48,6 +48,7 @@
|
||||
#include "opto/runtime.hpp"
|
||||
#include "opto/subnode.hpp"
|
||||
#include "prims/nativeLookup.hpp"
|
||||
#include "prims/unsafe.hpp"
|
||||
#include "runtime/sharedRuntime.hpp"
|
||||
#include "trace/traceMacros.hpp"
|
||||
|
||||
@ -2306,9 +2307,6 @@ void LibraryCallKit::insert_pre_barrier(Node* base_oop, Node* offset,
|
||||
}
|
||||
|
||||
|
||||
// Interpret Unsafe.fieldOffset cookies correctly:
|
||||
extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset);
|
||||
|
||||
const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type, bool is_native_ptr) {
|
||||
// Attempt to infer a sharper value type from the offset and base type.
|
||||
ciKlass* sharpened_klass = NULL;
|
||||
@ -4466,7 +4464,7 @@ bool LibraryCallKit::inline_fp_conversions(vmIntrinsics::ID id) {
|
||||
}
|
||||
|
||||
//----------------------inline_unsafe_copyMemory-------------------------
|
||||
// public native void Unsafe.copyMemory(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
|
||||
// public native void Unsafe.copyMemory0(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
|
||||
bool LibraryCallKit::inline_unsafe_copyMemory() {
|
||||
if (callee()->is_static()) return false; // caller must have the capability!
|
||||
null_check_receiver(); // null-check receiver
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
#include "oops/symbol.hpp"
|
||||
#include "prims/jvm_misc.hpp"
|
||||
#include "prims/nativeLookup.hpp"
|
||||
#include "prims/unsafe.hpp"
|
||||
#include "runtime/arguments.hpp"
|
||||
#include "runtime/handles.inline.hpp"
|
||||
#include "runtime/javaCalls.hpp"
|
||||
@ -107,8 +108,6 @@ char* NativeLookup::long_jni_name(const methodHandle& method) {
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void JNICALL JVM_RegisterJDKInternalMiscUnsafeMethods(JNIEnv *env, jclass unsafecls);
|
||||
void JNICALL JVM_RegisterSunMiscUnsafeMethods(JNIEnv *env, jclass unsafecls);
|
||||
void JNICALL JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass unsafecls);
|
||||
void JNICALL JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass);
|
||||
void JNICALL JVM_RegisterWhiteBoxMethods(JNIEnv *env, jclass wbclass);
|
||||
@ -123,7 +122,6 @@ extern "C" {
|
||||
|
||||
static JNINativeMethod lookup_special_native_methods[] = {
|
||||
{ CC"Java_jdk_internal_misc_Unsafe_registerNatives", NULL, FN_PTR(JVM_RegisterJDKInternalMiscUnsafeMethods) },
|
||||
{ CC"Java_sun_misc_Unsafe_registerNatives", NULL, FN_PTR(JVM_RegisterSunMiscUnsafeMethods) },
|
||||
{ CC"Java_java_lang_invoke_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) },
|
||||
{ CC"Java_jdk_internal_perf_Perf_registerNatives", NULL, FN_PTR(JVM_RegisterPerfMethods) },
|
||||
{ CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) },
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
39
hotspot/src/share/vm/prims/unsafe.hpp
Normal file
39
hotspot/src/share/vm/prims/unsafe.hpp
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef SHARE_VM_PRIMS_UNSAFE_HPP
|
||||
#define SHARE_VM_PRIMS_UNSAFE_HPP
|
||||
|
||||
#include "jni.h"
|
||||
|
||||
extern "C" {
|
||||
void JNICALL JVM_RegisterJDKInternalMiscUnsafeMethods(JNIEnv *env, jclass unsafecls);
|
||||
}
|
||||
|
||||
jlong Unsafe_field_offset_to_byte_offset(jlong field_offset);
|
||||
|
||||
jlong Unsafe_field_offset_from_byte_offset(jlong byte_offset);
|
||||
|
||||
#endif // SHARE_VM_PRIMS_UNSAFE_HPP
|
||||
@ -521,9 +521,9 @@ class RuntimeHistogramElement : public HistogramElement {
|
||||
JNI_ENTRY_NO_PRESERVE(result_type, header) \
|
||||
WeakPreserveExceptionMark __wem(thread);
|
||||
|
||||
#define JNI_ENTRY_NO_PRESERVE(result_type, header) \
|
||||
#define JNI_ENTRY_NO_PRESERVE(result_type, header) \
|
||||
extern "C" { \
|
||||
result_type JNICALL header { \
|
||||
result_type JNICALL header { \
|
||||
JavaThread* thread=JavaThread::thread_from_jni_environment(env); \
|
||||
assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \
|
||||
ThreadInVMfromNative __tiv(thread); \
|
||||
@ -535,7 +535,7 @@ extern "C" { \
|
||||
// a GC, is called outside the NoHandleMark (set via VM_QUICK_ENTRY_BASE).
|
||||
#define JNI_QUICK_ENTRY(result_type, header) \
|
||||
extern "C" { \
|
||||
result_type JNICALL header { \
|
||||
result_type JNICALL header { \
|
||||
JavaThread* thread=JavaThread::thread_from_jni_environment(env); \
|
||||
assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \
|
||||
ThreadInVMfromNative __tiv(thread); \
|
||||
@ -545,7 +545,7 @@ extern "C" { \
|
||||
|
||||
#define JNI_LEAF(result_type, header) \
|
||||
extern "C" { \
|
||||
result_type JNICALL header { \
|
||||
result_type JNICALL header { \
|
||||
JavaThread* thread=JavaThread::thread_from_jni_environment(env); \
|
||||
assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \
|
||||
VM_LEAF_BASE(result_type, header)
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
#include "gc/shared/cardTableModRefBS.hpp"
|
||||
#include "memory/resourceArea.hpp"
|
||||
#include "oops/method.hpp"
|
||||
#include "prims/unsafe.hpp"
|
||||
#include "runtime/os.hpp"
|
||||
#include "runtime/synchronizer.hpp"
|
||||
#include "runtime/thread.hpp"
|
||||
@ -326,7 +327,6 @@ Value* SharkBuilder::fabs() {
|
||||
}
|
||||
|
||||
Value* SharkBuilder::unsafe_field_offset_to_byte_offset() {
|
||||
extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset);
|
||||
return make_function((address) Unsafe_field_offset_to_byte_offset, "l", "l");
|
||||
}
|
||||
|
||||
|
||||
@ -33,8 +33,8 @@
|
||||
* -XX:+WhiteBoxAPI
|
||||
* -XX:DisableIntrinsic=_putCharVolatile,_putInt
|
||||
* -XX:DisableIntrinsic=_putIntVolatile
|
||||
* -XX:CompileCommand=option,sun.misc.Unsafe::putChar,ccstrlist,DisableIntrinsic,_getCharVolatile,_getInt
|
||||
* -XX:CompileCommand=option,sun.misc.Unsafe::putCharVolatile,ccstrlist,DisableIntrinsic,_getIntVolatile
|
||||
* -XX:CompileCommand=option,jdk.internal.misc.Unsafe::putChar,ccstrlist,DisableIntrinsic,_getCharVolatile,_getInt
|
||||
* -XX:CompileCommand=option,jdk.internal.misc.Unsafe::putCharVolatile,ccstrlist,DisableIntrinsic,_getIntVolatile
|
||||
* IntrinsicDisabledTest
|
||||
*/
|
||||
|
||||
@ -60,7 +60,7 @@ public class IntrinsicDisabledTest {
|
||||
return Boolean.valueOf(Objects.toString(wb.getVMFlag("TieredCompilation")));
|
||||
}
|
||||
|
||||
/* This test uses several methods from sun.misc.Unsafe. The method
|
||||
/* This test uses several methods from jdk.internal.misc.Unsafe. The method
|
||||
* getMethod() returns a different Executable for each different
|
||||
* combination of its input parameters. There are eight possible
|
||||
* combinations, getMethod can return an Executable representing
|
||||
@ -74,7 +74,7 @@ public class IntrinsicDisabledTest {
|
||||
String methodTypeName = isChar ? "Char" : "Int";
|
||||
|
||||
try {
|
||||
Class aClass = Class.forName("sun.misc.Unsafe");
|
||||
Class aClass = Class.forName("jdk.internal.misc.Unsafe");
|
||||
if (isPut) {
|
||||
aMethod = aClass.getDeclaredMethod("put" + methodTypeName + (isVolatile ? "Volatile" : ""),
|
||||
Object.class,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user