Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8236329 | 15 | Ioi Lam | P4 | Resolved | Fixed | team |
Thread::current is supposed to be quick, but we still call it TONS of times. E.g., when running with "java -version", on my machine it executes about 116,000,000 instructions (according to linux "perf stat -r 100 java -version". Thread::current() is called about 130000 times (see patch below), which leaves about less than 1000 instructions between each call to Thread::current(). So even if each call of Thread::current() takes just 10 instructions, that would add up to 1% of total instructions.
Many of these calls are unnecessary. The calls below are supposed to be used for debug builds only, but they are unintentionally included into the product build.
http://hg.openjdk.java.net/jdk/jdk/file/66211c44e126/src/hotspot/share/runtime/mutex.cpp#l159
void Mutex::unlock() {
assert_owner(Thread::current());
set_owner(NULL);
_lock.unlock();
}
void Monitor::notify() {
assert_owner(Thread::current());
_lock.notify();
}
void Monitor::notify_all() {
assert_owner(Thread::current());
_lock.notify_all();
}
Removing these from the product build reduces the calls by about 15,000 times. On my machine 'java -version' is about 0.6% faster.
Before: 0.0420053188 sec
After: 0.0417649239 sec
~ 99.42770374%
-----------
The patch for counting Thread:current() calls is in the attachment. Actual numbers variy depending on the number of compiler threads, etc.
Before:
$ bin/java -version
java version "14-internal" 2020-03-17
Java(TM) SE Runtime Environment (build 14-internal+0-adhoc.iklam.open)
Java HotSpot(TM) 64-Bit Server VM (build 14-internal+0-adhoc.iklam.open, mixed mode, sharing)
Thread::current() calls = 133886
After:
$ bin/java -version
java version "14-internal" 2020-03-17
Java(TM) SE Runtime Environment (build 14-internal+0-adhoc.iklam.open)
Java HotSpot(TM) 64-Bit Server VM (build 14-internal+0-adhoc.iklam.open, mixed mode, sharing)
Thread::current() calls = 118860
Many of these calls are unnecessary. The calls below are supposed to be used for debug builds only, but they are unintentionally included into the product build.
http://hg.openjdk.java.net/jdk/jdk/file/66211c44e126/src/hotspot/share/runtime/mutex.cpp#l159
void Mutex::unlock() {
assert_owner(Thread::current());
set_owner(NULL);
_lock.unlock();
}
void Monitor::notify() {
assert_owner(Thread::current());
_lock.notify();
}
void Monitor::notify_all() {
assert_owner(Thread::current());
_lock.notify_all();
}
Removing these from the product build reduces the calls by about 15,000 times. On my machine 'java -version' is about 0.6% faster.
Before: 0.0420053188 sec
After: 0.0417649239 sec
~ 99.42770374%
-----------
The patch for counting Thread:current() calls is in the attachment. Actual numbers variy depending on the number of compiler threads, etc.
Before:
$ bin/java -version
java version "14-internal" 2020-03-17
Java(TM) SE Runtime Environment (build 14-internal+0-adhoc.iklam.open)
Java HotSpot(TM) 64-Bit Server VM (build 14-internal+0-adhoc.iklam.open, mixed mode, sharing)
Thread::current() calls = 133886
After:
$ bin/java -version
java version "14-internal" 2020-03-17
Java(TM) SE Runtime Environment (build 14-internal+0-adhoc.iklam.open)
Java HotSpot(TM) 64-Bit Server VM (build 14-internal+0-adhoc.iklam.open, mixed mode, sharing)
Thread::current() calls = 118860
- backported by
-
JDK-8236329 Remove unnecessary calls to Thread::current
-
- Resolved
-
- relates to
-
JDK-8235678 Remove unnecessary calls to Thread::current() in MutexLocker calls
-
- Resolved
-