Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope locals next #34

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -186,8 +186,8 @@ JVM_RegisterLambdaProxyClassForArchiving
JVM_RegisterSignal
JVM_ReleaseUTF
JVM_ResumeThread
JVM_ScopedCache
JVM_SetScopedCache
JVM_ScopeLocalCache
JVM_SetScopeLocalCache
JVM_SetArrayElement
JVM_SetClassSigners
JVM_SetNativeThreadName
@@ -154,7 +154,7 @@ bool Compiler::is_intrinsic_supported(const methodHandle& method) {
case vmIntrinsics::_isPrimitive:
case vmIntrinsics::_currentThread0:
case vmIntrinsics::_currentThread:
case vmIntrinsics::_scopedCache:
case vmIntrinsics::_scopeLocalCache:
case vmIntrinsics::_dabs:
case vmIntrinsics::_dsqrt:
case vmIntrinsics::_dsin:
@@ -1427,11 +1427,11 @@ void LIRGenerator::do_getObjectSize(Intrinsic* x) {
__ branch_destination(L_done->label());
}

void LIRGenerator::do_scopedCache(Intrinsic* x) {
void LIRGenerator::do_scopeLocalCache(Intrinsic* x) {
assert(x->number_of_arguments() == 0, "wrong type");
LIR_Opr temp = new_register(T_ADDRESS);
LIR_Opr reg = rlock_result(x);
__ move(new LIR_Address(getThreadPointer(), in_bytes(JavaThread::scopedCache_offset()), T_ADDRESS), temp);
__ move(new LIR_Address(getThreadPointer(), in_bytes(JavaThread::scopeLocalCache_offset()), T_ADDRESS), temp);
// threadObj = ((OopHandle)_vthread)->resolve();
access_load(IN_NATIVE, T_OBJECT,
LIR_OprFact::address(new LIR_Address(temp, T_OBJECT)), reg);
@@ -3160,7 +3160,7 @@ void LIRGenerator::do_Intrinsic(Intrinsic* x) {
case vmIntrinsics::_getObjectSize: do_getObjectSize(x); break;
case vmIntrinsics::_currentThread0: do_currentThread0(x); break;
case vmIntrinsics::_currentThread: do_vthread(x); break;
case vmIntrinsics::_scopedCache: do_scopedCache(x); break;
case vmIntrinsics::_scopeLocalCache: do_scopeLocalCache(x); break;

case vmIntrinsics::_dlog: // fall through
case vmIntrinsics::_dlog10: // fall through
@@ -254,7 +254,7 @@ class LIRGenerator: public InstructionVisitor, public BlockClosure {
void do_getClass(Intrinsic* x);
void do_getObjectSize(Intrinsic* x);
void do_currentThread0(Intrinsic* x);
void do_scopedCache(Intrinsic* x);
void do_scopeLocalCache(Intrinsic* x);
void do_vthread(Intrinsic* x);
void do_FmaIntrinsic(Intrinsic* x);
void do_MathIntrinsic(Intrinsic* x);
@@ -77,7 +77,7 @@ bool vmIntrinsics::preserves_state(vmIntrinsics::ID id) {
case vmIntrinsics::_isInstance:
case vmIntrinsics::_currentThread0:
case vmIntrinsics::_currentThread:
case vmIntrinsics::_scopedCache:
case vmIntrinsics::_scopeLocalCache:
case vmIntrinsics::_dabs:
case vmIntrinsics::_fabs:
case vmIntrinsics::_iabs:
@@ -123,8 +123,8 @@ bool vmIntrinsics::can_trap(vmIntrinsics::ID id) {
case vmIntrinsics::_longBitsToDouble:
case vmIntrinsics::_currentThread0:
case vmIntrinsics::_currentThread:
case vmIntrinsics::_scopedCache:
case vmIntrinsics::_setScopedCache:
case vmIntrinsics::_scopeLocalCache:
case vmIntrinsics::_setScopeLocalCache:
case vmIntrinsics::_setCurrentThread:
case vmIntrinsics::_dabs:
case vmIntrinsics::_fabs:
@@ -257,8 +257,8 @@ bool vmIntrinsics::disabled_by_jvm_flags(vmIntrinsics::ID id) {
case vmIntrinsics::_currentThread:
if (!InlineThreadNatives) return true;
break;
case vmIntrinsics::_scopedCache:
case vmIntrinsics::_setScopedCache:
case vmIntrinsics::_scopeLocalCache:
case vmIntrinsics::_setScopeLocalCache:
case vmIntrinsics::_setCurrentThread:
case vmIntrinsics::_floatToRawIntBits:
case vmIntrinsics::_intBitsToFloat:
@@ -234,18 +234,18 @@ class methodHandle;
do_signature(arraycopy_signature, "(Ljava/lang/Object;ILjava/lang/Object;II)V") \
\
do_intrinsic(_currentThread0, java_lang_Thread, currentThread0_name, currentThread_signature, F_S) \
do_intrinsic(_currentThread, java_lang_Thread, currentThread_name, currentThread_signature, F_S) \
do_intrinsic(_scopedCache, java_lang_Thread, scopedCache_name, scopedCache_signature, F_S) \
do_intrinsic(_setScopedCache, java_lang_Thread, setScopedCache_name, setScopedCache_signature, F_S) \
do_intrinsic(_currentThread, java_lang_Thread, currentThread_name, currentThread_signature, F_S) \
do_intrinsic(_scopeLocalCache, java_lang_Thread, scopeLocalCache_name, scopeLocalCache_signature, F_S) \
do_intrinsic(_setScopeLocalCache, java_lang_Thread, setScopeLocalCache_name, setScopeLocalCache_signature, F_S) \
do_intrinsic(_setCurrentThread, java_lang_Thread, setCurrentThread_name, thread_void_signature, F_RN) \
do_name( currentThread0_name, "currentThread0") \
do_name( currentThread_name, "currentThread") \
do_name( scopedCache_name, "scopedCache") \
do_name( setScopedCache_name, "setScopedCache") \
do_name( scopeLocalCache_name, "scopeLocalCache") \
do_name( setScopeLocalCache_name, "setScopeLocalCache") \
do_name( setCurrentThread_name, "setCurrentThread") \
do_signature(currentThread_signature, "()Ljava/lang/Thread;") \
do_signature(scopedCache_signature, "()[Ljava/lang/Object;") \
do_signature(setScopedCache_signature, "([Ljava/lang/Object;)V") \
do_signature(scopeLocalCache_signature, "()[Ljava/lang/Object;") \
do_signature(setScopeLocalCache_signature, "([Ljava/lang/Object;)V") \
\
/* reflective intrinsics, for java/lang/Class, etc. */ \
do_intrinsic(_isAssignableFrom, java_lang_Class, isAssignableFrom_name, class_boolean_signature, F_RN) \
@@ -238,10 +238,10 @@ JVM_CallStackWalk(JNIEnv *env, jobject stackStream, jlong mode,
jint frame_count, jint start_index, jobjectArray frames);

JNIEXPORT jobject JNICALL
JVM_ScopedCache(JNIEnv *env, jclass threadClass);
JVM_ScopeLocalCache(JNIEnv *env, jclass threadClass);

JNIEXPORT void JNICALL
JVM_SetScopedCache(JNIEnv *env, jclass threadClass, jobject theCache);
JVM_SetScopeLocalCache(JNIEnv *env, jclass threadClass, jobject theCache);

JNIEXPORT jobject JNICALL
JVM_Vthread(JNIEnv *env, jclass threadClass);
@@ -587,8 +587,8 @@ bool C2Compiler::is_intrinsic_supported(const methodHandle& method, bool is_virt
case vmIntrinsics::_fullFence:
case vmIntrinsics::_currentThread0:
case vmIntrinsics::_currentThread:
case vmIntrinsics::_scopedCache:
case vmIntrinsics::_setScopedCache:
case vmIntrinsics::_scopeLocalCache:
case vmIntrinsics::_setScopeLocalCache:
case vmIntrinsics::_setCurrentThread:
#ifdef JFR_HAVE_INTRINSICS
case vmIntrinsics::_counterTime:
@@ -468,8 +468,8 @@ bool LibraryCallKit::try_to_inline(int predicate) {
case vmIntrinsics::_currentThread: return inline_native_currentThread();
case vmIntrinsics::_setCurrentThread: return inline_native_setCurrentThread();

case vmIntrinsics::_scopedCache: return inline_native_scopedCache();
case vmIntrinsics::_setScopedCache: return inline_native_setScopedCache();
case vmIntrinsics::_scopeLocalCache: return inline_native_scopeLocalCache();
case vmIntrinsics::_setScopeLocalCache: return inline_native_setScopeLocalCache();

#ifdef JFR_HAVE_INTRINSICS
case vmIntrinsics::_counterTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, JFR_TIME_FUNCTION), "counterTime");
@@ -3037,38 +3037,38 @@ bool LibraryCallKit::inline_native_currentThread0() {
return true;
}

Node* LibraryCallKit::scopedCache_helper() {
Node* LibraryCallKit::scopeLocalCache_helper() {
ciKlass *objects_klass = ciObjArrayKlass::make(env()->Object_klass());
const TypeOopPtr *etype = TypeOopPtr::make_from_klass(env()->Object_klass());

bool xk = etype->klass_is_exact();

Node* thread = _gvn.transform(new ThreadLocalNode());
Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(JavaThread::scopedCache_offset()));
Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(JavaThread::scopeLocalCache_offset()));
return _gvn.transform(make_load(NULL, p, p->bottom_type()->is_ptr(),
T_ADDRESS, MemNode::unordered));
}

//------------------------inline_native_scopedCache------------------
bool LibraryCallKit::inline_native_scopedCache() {
//------------------------inline_native_scopeLocalCache------------------
bool LibraryCallKit::inline_native_scopeLocalCache() {
ciKlass *objects_klass = ciObjArrayKlass::make(env()->Object_klass());
const TypeOopPtr *etype = TypeOopPtr::make_from_klass(env()->Object_klass());
const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);

// Because we create the scoped cache lazily we have to make the
// Because we create the scopeLocal cache lazily we have to make the
// type of the result BotPTR.
bool xk = etype->klass_is_exact();
const Type* objects_type = TypeAryPtr::make(TypePtr::BotPTR, arr0, objects_klass, xk, 0);
Node* cache_obj_handle = scopedCache_helper();
Node* cache_obj_handle = scopeLocalCache_helper();
set_result(access_load(cache_obj_handle, objects_type, T_OBJECT, IN_NATIVE));

return true;
}

//------------------------inline_native_setScopedCache------------------
bool LibraryCallKit::inline_native_setScopedCache() {
//------------------------inline_native_setScopeLocalCache------------------
bool LibraryCallKit::inline_native_setScopeLocalCache() {
Node* arr = argument(0);
Node* cache_obj_handle = scopedCache_helper();
Node* cache_obj_handle = scopeLocalCache_helper();

const TypePtr *adr_type = _gvn.type(cache_obj_handle)->isa_ptr();
store_to_memory(control(), cache_obj_handle, arr, T_OBJECT, adr_type,
@@ -233,9 +233,9 @@ class LibraryCallKit : public GraphKit {
bool inline_unsafe_writebackSync0(bool is_pre);
bool inline_unsafe_copyMemory();
bool inline_native_currentThread0();
bool inline_native_scopedCache();
Node* scopedCache_helper();
bool inline_native_setScopedCache();
bool inline_native_scopeLocalCache();
Node* scopeLocalCache_helper();
bool inline_native_setScopeLocalCache();
bool inline_native_currentThread();
bool inline_native_setCurrentThread();

@@ -826,7 +826,7 @@ bool LoadNode::is_immutable_value(Node* adr) {
in_bytes(JavaThread::osthread_offset()),
in_bytes(JavaThread::threadObj_offset()),
in_bytes(JavaThread::vthread_offset()),
in_bytes(JavaThread::scopedCache_offset()),
in_bytes(JavaThread::scopeLocalCache_offset()),
};

for (size_t i = 0; i < sizeof offsets / sizeof offsets[0]; i++) {
@@ -3127,22 +3127,22 @@ JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread))
}
JVM_END

JVM_ENTRY(jobject, JVM_ScopedCache(JNIEnv* env, jclass threadClass))
oop theCache = thread->scopedCache();
JVM_ENTRY(jobject, JVM_ScopeLocalCache(JNIEnv* env, jclass threadClass))
oop theCache = thread->scopeLocalCache();
if (theCache) {
arrayOop objs = arrayOop(theCache);
assert(objs->length() == ScopedCacheSize * 2, "wrong length");
assert(objs->length() == ScopeLocalCacheSize * 2, "wrong length");
}
return JNIHandles::make_local(THREAD, theCache);
JVM_END

JVM_ENTRY(void, JVM_SetScopedCache(JNIEnv* env, jclass threadClass,
JVM_ENTRY(void, JVM_SetScopeLocalCache(JNIEnv* env, jclass threadClass,
jobject theCache))
arrayOop objs = arrayOop(JNIHandles::resolve(theCache));
if (objs != NULL) {
assert(objs->length() == ScopedCacheSize * 2, "wrong length");
assert(objs->length() == ScopeLocalCacheSize * 2, "wrong length");
}
thread->set_scopedCache(objs);
thread->set_scopeLocalCache(objs);
JVM_END

JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
@@ -1071,11 +1071,11 @@ void JavaThread::set_threadOopHandles(oop p) {
assert(_thread_oop_storage != NULL, "not yet initialized");
_threadObj = OopHandle(_thread_oop_storage, p);
_vthread = OopHandle(_thread_oop_storage, p);
_scopedCache = OopHandle(_thread_oop_storage, NULL);
_scopeLocalCache = OopHandle(_thread_oop_storage, NULL);
}

oop JavaThread::scopedCache() const {
return _scopedCache.resolve();
oop JavaThread::scopeLocalCache() const {
return _scopeLocalCache.resolve();
}

oop JavaThread::vthread() const {
@@ -1087,9 +1087,9 @@ void JavaThread::set_vthread(oop p) {
_vthread.replace(p);
}

void JavaThread::set_scopedCache(oop p) {
void JavaThread::set_scopeLocalCache(oop p) {
assert(_thread_oop_storage != NULL, "not yet initialized");
_scopedCache.replace(p);
_scopeLocalCache.replace(p);
}

OopStorage* JavaThread::thread_oop_storage() {
@@ -2307,7 +2307,7 @@ void JavaThread::deoptimize() {
// search for the current bci in that string.
address pc = fst.current()->pc();
nmethod* nm = (nmethod*) fst.current()->cb();
ScopeDesc* sd = nm->scope_desc_at(pc);
ScopeLocalesc* sd = nm->scope_desc_at(pc);
char buffer[8];
jio_snprintf(buffer, sizeof(buffer), "%d", sd->bci());
size_t len = strlen(buffer);
@@ -882,7 +882,7 @@ class JavaThread: public Thread {
bool _on_thread_list; // Is set when this JavaThread is added to the Threads list
OopHandle _threadObj; // The Java level thread object
OopHandle _vthread;
OopHandle _scopedCache;
OopHandle _scopeLocalCache;

#ifdef ASSERT
private:
@@ -1099,9 +1099,9 @@ class JavaThread: public Thread {

public:
oop _mounted_vthread;
jlong _scoped_hash_table_shift;
jlong _scopeLocal_hash_table_shift;

void allocate_scoped_hash_table(int count);
void allocate_scopeLocal_hash_table(int count);

public:
// Constructor
@@ -1155,8 +1155,8 @@ class JavaThread: public Thread {
void set_threadOopHandles(oop p);
oop vthread() const;
void set_vthread(oop p);
oop scopedCache() const;
void set_scopedCache(oop p);
oop scopeLocalCache() const;
void set_scopeLocalCache(oop p);
oop mounted_vthread() const { return _mounted_vthread; }
void set_mounted_vthread(oop p) { _mounted_vthread = p; }

@@ -1478,7 +1478,7 @@ class JavaThread: public Thread {
void clr_do_not_unlock(void) { _do_not_unlock_if_synchronized = false; }
bool do_not_unlock(void) { return _do_not_unlock_if_synchronized; }

static ByteSize scopedCache_offset() { return byte_offset_of(JavaThread, _scopedCache); }
static ByteSize scopeLocalCache_offset() { return byte_offset_of(JavaThread, _scopeLocalCache); }

// For assembly stub generation
static ByteSize threadObj_offset() { return byte_offset_of(JavaThread, _threadObj); }
@@ -750,7 +750,7 @@ typedef HashtableEntry<InstanceKlass*, mtClass> KlassHashtableEntry;
nonstatic_field(NamedThread, _processed_thread, Thread*) \
nonstatic_field(JavaThread, _threadObj, OopHandle) \
nonstatic_field(JavaThread, _vthread, OopHandle) \
nonstatic_field(JavaThread, _scopedCache, OopHandle) \
nonstatic_field(JavaThread, _scopeLocalCache, OopHandle) \
nonstatic_field(JavaThread, _anchor, JavaFrameAnchor) \
nonstatic_field(JavaThread, _vm_result, oop) \
nonstatic_field(JavaThread, _vm_result_2, Metadata*) \
@@ -154,7 +154,7 @@ private static Thread currentCarrierThread() {
private int stackWatermark;
private int refStackWatermark;

private Object[] scopedCache;
private Object[] scopeLocalCache;

// private long[] nmethods = null; // grows up
// private int numNmethods = 0;
@@ -290,12 +290,12 @@ private Continuation innermost() {
private void mount() {
if (!compareAndSetMounted(false, true))
throw new IllegalStateException("Mounted!!!!");
Thread.setScopedCache(scopedCache);
Thread.setScopeLocalCache(scopeLocalCache);
}

private void unmount() {
scopedCache = Thread.scopedCache();
Thread.setScopedCache(null);
scopeLocalCache = Thread.scopeLocalCache();
Thread.setScopeLocalCache(null);
setMounted(false);
}