On Tue, 9 Feb 2021 15:40:03 GMT, Aleksey Shipilev <sh...@openjdk.org> wrote:

> `JVM_LatestUserDefinedLoader` is called normally from 
> `ObjectInputStream.resolveClass` -> `VM.latestUserDefinedLoader0`. And it 
> takes a measurable time to walk the stack. There is JDK-8173368 that wants to 
> replace it with `StackWalker`, but we can tune up the 
> `JVM_LatestUserDefinedLoader` itself without changing the semantics of it 
> (thus providing the backportability, including the releases that do not have 
> `StackWalker`) and improving performance (thus providing a more aggressive 
> baseline for `StackWalker` rewrite).
> 
> The key is to recognize that out of two checks: 1) checking for two special 
> subclasses; 2) checking for user classloader -- the first one usually passes, 
> and second one fails much more frequently. First check also requires 
> traversing the superclasses upwards looking for match. Reversing the order of 
> the checks, plus inlining the helper method improves performance without 
> changing the semantics.
> 
> Out of curiosity, my previous patch dropped the first check completely, 
> replacing it by asserts, and we definitely run into situation where that 
> check is needed on some tests.
> 
> On my machine, `VM.latestUserDefinedLoader` invocation time drops from 115 to 
> 100 ns/op. Single-threaded SPECjvm2008:serial improves about 3% with this 
> patch.
> 
> Additional testing:
>  - [x] Ad-hoc benchmarks
>  - [x] Linux x86_64 fastdebug, `tier1`, `tier2`, `tier3` 
> 
> ---------
> ### Progress
> - [x] Change must not contain extraneous whitespace
> - [x] Commit message must refer to an issue
> - [ ] Change must be properly reviewed
> 
> 
> 
> ### Download
> `$ git fetch https://git.openjdk.java.net/jdk pull/2485/head:pull/2485`
> `$ git checkout pull/2485`

Hi Aleksey,

This seems reasonable to me. The generated reflection classes are loaded by a 
temporary loader (so they can be unloaded) and so have to be skipped.

I've added core-libs to the PR as this is the VM side of their code and I want 
to make sure nothing has been overlooked.

Thanks,
David

src/hotspot/share/prims/jvm.cpp line 3293:

> 3291:     oop loader = ik->class_loader();
> 3292:     if (loader != NULL && 
> !SystemDictionary::is_platform_class_loader(loader)) {
> 3293:       if 
> (!ik->is_subclass_of(vmClasses::reflect_MethodAccessorImpl_klass()) &&

Please add a comment:
// Skip reflection related frames

-------------

Marked as reviewed by dholmes (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/2485

Reply via email to