RFR: 8358580: Rethink how classes are kept alive in training data
Aleksey Shipilev
shade at openjdk.org
Thu Jul 10 08:38:39 UTC 2025
On Thu, 10 Jul 2025 02:37:05 GMT, Igor Veresov <iveresov at openjdk.org> wrote:
> Use OopStorage directly instead of JNI handles. Note that we never destroy TrainingData objects, so we don't need to concern ourselves with freeing the OopStorage entries. Also, keeping the klasses alive is only necessary during the training run. During the replay the klasses TD objects refer to are always alive.
src/hotspot/share/oops/trainingData.cpp line 437:
> 435: KlassTrainingData::KlassTrainingData(InstanceKlass* klass) : TrainingData(klass) {
> 436: assert(klass != nullptr, "");
> 437: oop* handle = oop_storage()->allocate();
I don't think you are supposed to allocate from `OopStorage` directly, that's the job for various `Handle`-s. Also, capturing the `java_mirror` does not really block the unloading, see:
// Loading the java_mirror does not keep its holder alive. See Klass::keep_alive().
inline oop Klass::java_mirror() const {
return _java_mirror.resolve();
}
So the idiomatic way would be:
_holder_mirror = OopHandle(Universe::vm_global(), klass->klass_holder());
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26233#discussion_r2196997605
More information about the hotspot-dev
mailing list