JDK-8253920 : Share method trampolines in CDS dynamic archive
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-10-02
  • Updated: 2021-02-09
  • Resolved: 2020-10-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 16
16 b22Fixed
Related Reports
Duplicate :  
Relates :  
Description
Currently, apps using CDS dynamic archive (-XX:ArchiveClassesAtExit) have slower start-up time than the same apps using CDS static archive (-Xshare:dump). One reason is that DynamicArchiveBuilder::make_trampolines() allocates a separate trampoline for each Method:

https://github.com/iklam/jdk/blob/cfd41c0c1dfae823d465711d147373c343977f00/src/hotspot/share/memory/dynamicArchive.cpp#L353

At run time, whenever an archived Method is linked, we need to compile a trampoline call using SharedRuntime::generate_trampoline(). This is a slow operation.

https://github.com/iklam/jdk/blob/cfd41c0c1dfae823d465711d147373c343977f00/src/hotspot/share/runtime/sharedRuntime.cpp#L2612

In contrast, in the static archive, archived Methods with the same AdapterHandlerEntry share the same trampoline. At run time, fewer calls to SharedRuntime::generate_trampoline() are made.
Comments
Changeset: 84e985da Author: Calvin Cheung <ccheung@openjdk.org> Date: 2020-10-27 16:16:01 +0000 URL: https://git.openjdk.java.net/jdk/commit/84e985da
27-10-2020

We should also use the same code for the static archive as well. That way, we can remove the use of CDSAdapterHandlerEntry and simplify the code. This will also be a basis for fixing JDK-8253495 (runtime/cds/DeterministicDump.java). Currently the creation order of CDSAdapterHandlerEntry depends on class loading order, which may vary due to thread concurrency. In contrast, in DynamicArchiveBuilder::allocate_trampolines(), we can iterate the MethodTrampolineInfos in a deterministic order to ensure that the trampolines are allocated in a deterministic order.
02-10-2020

Suggested implementation: class MethodTrampolineInfo { address c2i_entry_trampoline; AdapterHandlerEntry** adapter_trampoline; }; ResourceHashtable table maps {AdapterHandlerEntry -> MethodTrampolineInfo}; DynamicArchiveBuilder::estimate_trampoline_size() { size_t each_method_bytes = align_up(SharedRuntime::trampoline_size(), BytesPerWord) + align_up(sizeof(AdapterHandlerEntry*), BytesPerWord); int count = 0; for each Method m { // m is the "original" Method AdapterHandlerEntry* ent = m->adapter(); // different methods can share the same AdapterHandlerEntry MethodTrampolineInfo info = table->put_if_absent(ent, is_created); if (is_created) { count ++; } } result = count * each_method_bytes; } // This should be called inside DynamicArchiveBuilder::reserve_buffers_for_trampolines() void DynamicArchiveBuilder::allocate_trampolines() { for each Method m { // Walk the methods in a deterministic order so that the trampolines are // created in a deterministic order. AdapterHandlerEntry* ent = m->adapter(); MethodTrampolineInfo info = table->get(ent); if (info->c2i_entry_trampoline == NULL) { info->c2i_entry_trampoline = mc_region -> allocate(SharedRuntime::trampoline_size()); info->adapter_trampoline = mc_region->allocate(sizeof(AdapterHandlerEntry*)); } } } void DynamicArchiveBuilder::make_trampolines() { for each Method m { // m is the "copy" of the original Method, but it's adapter() field is still valid because // we haven't called make_klasses_shareable() yet. AdapterHandlerEntry* ent = m->adapter(); MethodTrampolineInfo info = table->get(ent); m->set_from_compiled_entry(.... info->c2i_entry_trampoline ....); m->set_adapter_trampoline(.... info->adapter_trampoline ); } }
02-10-2020