Skip to content

Commit

Permalink
JFR infrastructure for Loom
Browse files Browse the repository at this point in the history
  • Loading branch information
mgronlun committed Feb 2, 2020
1 parent 50b2668 commit ce6ad9b
Show file tree
Hide file tree
Showing 60 changed files with 1,119 additions and 451 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/share/c1/c1_Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ bool Compiler::is_intrinsic_supported(const methodHandle& method) {
case vmIntrinsics::_Continuation_runLevel:
#ifdef JFR_HAVE_INTRINSICS
case vmIntrinsics::_counterTime:
case vmIntrinsics::_getEventWriter:
//case vmIntrinsics::_getEventWriter:
#if defined(_LP64) || !defined(TRACE_ID_SHIFT)
case vmIntrinsics::_getClassId:
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/c1/c1_LIRGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2964,6 +2964,7 @@ void LIRGenerator::do_ClassIDIntrinsic(Intrinsic* x) {
__ move(id, rlock_result(x));
}

/*
void LIRGenerator::do_getEventWriter(Intrinsic* x) {
LabelObj* L_end = new LabelObj();
Expand All @@ -2981,6 +2982,7 @@ void LIRGenerator::do_getEventWriter(Intrinsic* x) {
__ branch_destination(L_end->label());
}
*/

#endif

Expand Down Expand Up @@ -3013,9 +3015,11 @@ void LIRGenerator::do_Intrinsic(Intrinsic* x) {
case vmIntrinsics::_getClassId:
do_ClassIDIntrinsic(x);
break;
/*
case vmIntrinsics::_getEventWriter:
do_getEventWriter(x);
break;
*/
case vmIntrinsics::_counterTime:
do_RuntimeCall(CAST_FROM_FN_PTR(address, JFR_TIME_FUNCTION), x);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/c1/c1_LIRGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ class LIRGenerator: public InstructionVisitor, public BlockClosure {

#ifdef JFR_HAVE_INTRINSICS
void do_ClassIDIntrinsic(Intrinsic* x);
void do_getEventWriter(Intrinsic* x);
// void do_getEventWriter(Intrinsic* x);
#endif

void do_RuntimeCall(address routine, Intrinsic* x);
Expand Down
18 changes: 10 additions & 8 deletions src/hotspot/share/classfile/javaClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2028,13 +2028,13 @@ void java_lang_ThreadGroup::serialize_offsets(SerializeClosure* f) {


// java_lang_VirtualThread

int java_lang_VirtualThread::static_notify_jvmti_events_offset = 0;
int java_lang_VirtualThread::_carrierThread_offset = 0;
int java_lang_VirtualThread::_continuation_offset = 0;
int java_lang_VirtualThread::_state_offset = 0;
int java_lang_VirtualThread::_jfrTraceId_offset = 0;

#define FIBER_FIELDS_DO(macro) \
#define VTHREAD_FIELDS_DO(macro) \
macro(static_notify_jvmti_events_offset, k, "notifyJvmtiEvents", bool_signature, true); \
macro(_carrierThread_offset, k, "carrierThread", thread_signature, false); \
macro(_continuation_offset, k, "cont", continuation_signature, false); \
Expand All @@ -2044,7 +2044,8 @@ static jboolean vthread_notify_jvmti_events = JNI_FALSE;

void java_lang_VirtualThread::compute_offsets() {
InstanceKlass* k = SystemDictionary::VirtualThread_klass();
FIBER_FIELDS_DO(FIELD_COMPUTE_OFFSET);
VTHREAD_FIELDS_DO(FIELD_COMPUTE_OFFSET);
VTHREAD_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
}

void java_lang_VirtualThread::init_static_notify_jvmti_events() {
Expand All @@ -2063,7 +2064,7 @@ oop java_lang_VirtualThread::carrier_thread(oop vthread) {
oop thread = vthread->obj_field(_carrierThread_offset);
return thread;
}

oop java_lang_VirtualThread::continuation(oop vthread) {
oop cont = vthread->obj_field(_continuation_offset);
return cont;
Expand Down Expand Up @@ -2101,7 +2102,8 @@ java_lang_Thread::ThreadStatus java_lang_VirtualThread::map_state_to_thread_stat

#if INCLUDE_CDS
void java_lang_VirtualThread::serialize_offsets(SerializeClosure* f) {
FIBER_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
VTHREAD_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
VTHREAD_INJECTED_FIELDS(INJECTED_FIELD_SERIALIZE_OFFSET);
}
#endif

Expand Down Expand Up @@ -2282,7 +2284,7 @@ class BacktraceBuilder: public StackObj {
_has_hidden_top_frame = get_has_hidden_top_frame(backtrace);
assert(_methods->length() == _bcis->length() &&
_methods->length() == _mirrors->length() &&
_mirrors->length() == _names->length() &&
_mirrors->length() == _names->length() &&
_names->length() == _conts->length(),
"method and source information arrays should match");

Expand Down Expand Up @@ -2857,7 +2859,7 @@ void java_lang_Throwable::get_stack_trace_elements(Handle throwable,
method,
bte._version,
bte._bci,
bte._name,
bte._name,
bte._cont,
CHECK);
}
Expand Down Expand Up @@ -4865,7 +4867,7 @@ bool java_lang_Continuation::on_local_stack(oop ref, address adr) {
void* base = s->base(T_INT);
return adr >= base && (char*)adr < ((char*)base + (s->length() * 4));
}

bool java_lang_Continuation::is_mounted(oop ref) {
return ref->bool_field(_mounted_offset) != 0;
}
Expand Down
13 changes: 10 additions & 3 deletions src/hotspot/share/classfile/javaClasses.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, 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
Expand Down Expand Up @@ -576,13 +576,17 @@ class java_lang_ThreadGroup : AllStatic {

// Interface to java.lang.VirtualThread objects

#define VTHREAD_INJECTED_FIELDS(macro) \
macro(java_lang_VirtualThread, jfrTraceId, long_signature, false)

class java_lang_VirtualThread : AllStatic {
private:
static int static_notify_jvmti_events_offset;
static int _carrierThread_offset;
static int _continuation_offset;
static int _state_offset;
// keep in sync with java.lang.VirtualThread
static int _jfrTraceId_offset;
enum {
NEW = 0,
STARTED = 1,
Expand Down Expand Up @@ -610,6 +614,8 @@ class java_lang_VirtualThread : AllStatic {
static java_lang_Thread::ThreadStatus map_state_to_thread_status(jshort state);
static void set_notify_jvmti_events(jboolean enable);
static void init_static_notify_jvmti_events();
static jlong jfrTraceId(oop vthread);
static jlong set_jfrTraceId(oop vthread, jlong id);
};


Expand Down Expand Up @@ -1076,7 +1082,7 @@ class java_lang_ContinuationScope: AllStatic {

static inline oop name(oop ref);
};

// Interface to java.lang.Continuation objects
class java_lang_Continuation: AllStatic {
friend class JavaClasses;
Expand Down Expand Up @@ -1937,7 +1943,8 @@ class InjectedField {
MEMBERNAME_INJECTED_FIELDS(macro) \
CALLSITECONTEXT_INJECTED_FIELDS(macro) \
STACKFRAMEINFO_INJECTED_FIELDS(macro) \
MODULE_INJECTED_FIELDS(macro)
MODULE_INJECTED_FIELDS(macro) \
VTHREAD_INJECTED_FIELDS(macro)

// Interface to hard-coded offset checking

Expand Down
11 changes: 10 additions & 1 deletion src/hotspot/share/classfile/javaClasses.inline.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, 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
Expand Down Expand Up @@ -292,6 +292,15 @@ inline bool java_lang_Continuation::done(oop ref) {
return ref->bool_field(_done_offset);
}

inline jlong java_lang_VirtualThread::jfrTraceId(oop ref) {
return ref->long_field(_jfrTraceId_offset);
}

inline jlong java_lang_VirtualThread::set_jfrTraceId(oop ref, jlong id) {
ref->long_field_put(_jfrTraceId_offset, id);
return id;
}

inline oop jdk_internal_misc_StackChunk::parent(oop ref) {
return ref->obj_field(_parent_offset);
}
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/classfile/vmSymbols.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, 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
Expand Down Expand Up @@ -403,6 +403,7 @@
template(done_name, "done") \
template(mounted_name, "mounted") \
template(numInterpretedFrames_name, "numInterpretedFrames") \
template(jfrTraceId_name, "jfrTraceId") \
template(fp_name, "fp") \
template(sp_name, "sp") \
template(pc_name, "pc") \
Expand Down
11 changes: 10 additions & 1 deletion src/hotspot/share/jfr/jfr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "precompiled.hpp"
#include "jfr/jfr.hpp"
#include "jfr/jni/jfrJavaSupport.hpp"
#include "jfr/leakprofiler/leakProfiler.hpp"
#include "jfr/periodic/sampling/jfrThreadSampler.hpp"
#include "jfr/recorder/jfrRecorder.hpp"
Expand Down Expand Up @@ -73,10 +74,18 @@ void Jfr::on_thread_start(Thread* t) {
JfrThreadLocal::on_start(t);
}

void Jfr::on_thread_start(jthread carrier_thread, jthread vthread) {
JfrThreadLocal::on_vthread_start(JfrJavaSupport::java_thread(carrier_thread), vthread);
}

void Jfr::on_thread_exit(Thread* t) {
JfrThreadLocal::on_exit(t);
}

void Jfr::on_thread_exit(jthread carrier_thread, jthread vthread) {
JfrThreadLocal::on_vthread_exit(JfrJavaSupport::java_thread(carrier_thread), vthread);
}

void Jfr::exclude_thread(Thread* t) {
JfrThreadLocal::exclude(t);
}
Expand All @@ -91,7 +100,7 @@ bool Jfr::is_excluded(Thread* t) {

void Jfr::on_java_thread_dismantle(JavaThread* jt) {
if (JfrRecorder::is_recording()) {
JfrCheckpointManager::write_thread_checkpoint(jt);
JfrCheckpointManager::write_checkpoint(jt);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/jfr/jfr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class Jfr : AllStatic {
static void on_create_vm_3();
static void on_unloading_classes();
static void on_thread_start(Thread* thread);
static void on_thread_start(jthread carrier_thread, jthread vthread);
static void on_thread_exit(Thread* thread);
static void on_thread_exit(jthread carrier_thread, jthread vthread);
static void on_java_thread_dismantle(JavaThread* jt);
static void on_vm_shutdown(bool exception_handler = false);
static bool on_flight_recorder_option(const JavaVMOption** option, char* delimiter);
Expand Down
Loading

0 comments on commit ce6ad9b

Please sign in to comment.