11/*
2- * Copyright (c) 1999, 2025 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 1999, 2026 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
4848#include " gc/shared/collectedHeap.inline.hpp"
4949#include " memory/allocation.inline.hpp"
5050#include " memory/universe.hpp"
51+ #include " oops/instanceKlass.hpp"
5152#include " oops/oop.inline.hpp"
5253#include " oops/trainingData.hpp"
5354#include " runtime/handles.inline.hpp"
@@ -83,6 +84,7 @@ ciObjectFactory::ciObjectFactory(Arena* arena,
8384 int expected_size)
8485 : _arena(arena),
8586 _ci_metadata(arena, expected_size, 0 , nullptr ),
87+ _cached_init_state(arena, _shared_ident_limit, 0 , (u1)0),
8688 _unloaded_methods(arena, 4 , 0 , nullptr ),
8789 _unloaded_klasses(arena, 8 , 0 , nullptr ),
8890 _unloaded_instances(arena, 4 , 0 , nullptr ),
@@ -97,6 +99,28 @@ ciObjectFactory::ciObjectFactory(Arena* arena,
9799 // If the shared ci objects exist append them to this factory's objects
98100 if (_shared_ci_metadata != nullptr ) {
99101 _ci_metadata.appendAll (_shared_ci_metadata);
102+ // ciInstanceKlass for well-known class is shared by all
103+ // compiler threads and can be updated concurrently by
104+ // other compiler threads during compilation.
105+ // Make local copy of class state to avoid state change
106+ // during compilation.
107+ int len = _ci_metadata.length ();
108+ for (int i = 0 ; i < len; i++) {
109+ ciMetadata* obj = _ci_metadata.at (i);
110+ if (obj->is_loaded () && obj->is_instance_klass ()) {
111+ ciInstanceKlass* cik = obj->as_instance_klass ();
112+ precond (cik->is_shared ());
113+ InstanceKlass::ClassState current_state = cik->_init_state ;
114+ InstanceKlass::ClassState state = InstanceKlass::fully_initialized;
115+ if (current_state != state) {
116+ GUARDED_VM_ENTRY ( state = cik->get_instanceKlass ()->init_state (); )
117+ // Update state of shared ciInstanceKlass
118+ cik->_init_state = state;
119+ }
120+ // Cache state for current compilation
121+ _cached_init_state.at_put_grow (cik->ident (), (u1)state, 0 );
122+ }
123+ }
100124 }
101125}
102126
0 commit comments