If any issues arise, please don't hesitate to ask.
Before diving into the code, please clone the OpenJDK JDK repository on a machine running Linux and build it according to the build instructions.
This should give you a running OpenJDK. Add it to your path and run a simple Java "Hello, World" program to confirm everything is set up correctly.
Refer to the testing documentation for guidance. Download a pre-built JTReg JAR from this link:
wget https://builds.shipilev.net/jtreg/jtreg-7.4+1.zip
unzip jtreg-7.4+1.zip
Configure the tests:
bash configure --with-jtreg=jtreg --with-debug-level=fastdebug
This should allow you to run tests, such as the TestActiveSettingEvent
test:
make test TEST=jtreg:test/jdk/jdk/jfr/event/runtime/TestActiveSettingEvent.java
Try to get a rough understanding of what this test case does.
Our team is currently developing a new CPU time profiler for OpenJDK. The work-in-progress code can be found here.
The main files you’ll need for your task are:
These files contain the new CPU time sampler implementation, which should be understandable without extensive OpenJDK knowledge. To get started, here’s an annotated version of the header interface:
class JfrCPUTimeThreadSampling : public JfrCHeapObj {
friend class JfrRecorder;
/* ... */
public:
// Called externally to set the sampling rate
// rate == 0 stops the sampling
static void set_rate(double rate, bool autoadapt);
// Called whenever a Java thread is created
static void on_javathread_create(JavaThread* thread);
// Called whenever a Java thread is terminated
static void on_javathread_terminate(JavaThread* thread);
// Called in the signal handler for CPU time timer events
void handle_timer_signal(void* context);
// Prevents the queue from being processed,
// for specific test cases only, so it can be ignored
static void set_process_queue(bool process_queue);
};
Steps:
- Clone this branch and attempt to build it.
- Run the sampler, following the information here.
- Explore the relationship between all methods in the JfrCPUTimeThreadSampling class
- Try to understand how the sampler works. Feel free to use
printf
debugging or a debugger (e.g., vsreg). You can ignore the details of the stack walking.
A bug exists in this pull request. The TestActiveSettingEvent
test case (which doesn't involve the new sampler) fails, causing the JVM to become stuck in the disenroll
method indefinitely.
Do you have any ideas why? Feel free to use (printf) debugging. A hint: the fix is quite simple and requires only one line of code to be changed in jfrCPUTimeThreadSampler.cpp
, but it may not be entirely obvious.
CC-BY