15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "cds/aotReferenceObjSupport.hpp"
26 #include "cds/heapShared.hpp"
27 #include "classfile/javaClasses.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "classfile/systemDictionary.hpp"
30 #include "classfile/vmSymbols.hpp"
31 #include "logging/log.hpp"
32 #include "memory/resourceArea.hpp"
33 #include "memory/universe.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "oops/oopHandle.inline.hpp"
36 #include "runtime/fieldDescriptor.inline.hpp"
37 #include "runtime/javaCalls.hpp"
38 #include "utilities/hashTable.hpp"
39
40 // Handling of java.lang.ref.Reference objects in the AOT cache
41 // ============================================================
42 //
43 // When AOTArtifactFinder finds an oop which is a instance of java.lang.ref.Reference:
44 //
45 // - We check if the oop is eligible to be stored in the AOT cache. If not, the AOT cache
46 // creation fails -- see AOTReferenceObjSupport::check_if_ref_obj()
47 //
48 // - Otherwise, we store the oop into the AOT cache, but we unconditionally reset its
49 // "next" and "discovered" fields to null. Otherwise, if AOTArtifactFinder follows these
50 // fields, it may found unrelated objects that we don't intend to cache.
51 //
52 // Eligibility
53 // ===========
54 //
146 {
147 Symbol* cds_name = vmSymbols::jdk_internal_misc_CDS();
148 Klass* cds_klass = SystemDictionary::resolve_or_fail(cds_name, true /*throw error*/, CHECK);
149 TempNewSymbol method_name = SymbolTable::new_symbol("getKeepAliveObjects");
150 TempNewSymbol method_sig = SymbolTable::new_symbol("()[Ljava/lang/Object;");
151 JavaValue result(T_OBJECT);
152 JavaCalls::call_static(&result, cds_klass, method_name, method_sig, CHECK);
153
154 _keep_alive_objs_array = OopHandle(Universe::vm_global(), result.get_oop());
155 }
156
157 // Trigger a GC to prune eligible referents that were not kept alive
158 Universe::heap()->collect(GCCause::_java_lang_system_gc);
159 }
160 }
161
162 void AOTReferenceObjSupport::init_keep_alive_objs_table() {
163 assert_at_safepoint(); // _keep_alive_objs_table uses raw oops
164 oop a = _keep_alive_objs_array.resolve();
165 if (a != nullptr) {
166 precond(a->is_objArray());
167 precond(AOTReferenceObjSupport::is_enabled());
168 objArrayOop array = objArrayOop(a);
169
170 _keep_alive_objs_table = new (mtClass)KeepAliveObjectsTable();
171 for (int i = 0; i < array->length(); i++) {
172 oop obj = array->obj_at(i);
173 _keep_alive_objs_table->put(obj, true); // The array may have duplicated entries but that's OK.
174 }
175 }
176 }
177
178 // Returns true IFF obj is an instance of java.lang.ref.Reference. If so, perform extra eligibility checks.
179 bool AOTReferenceObjSupport::check_if_ref_obj(oop obj) {
180 assert_at_safepoint(); // _keep_alive_objs_table uses raw oops
181
182 if (obj->klass()->is_subclass_of(vmClasses::Reference_klass())) {
183 // The following check works only if the java.lang.ref.Reference$ReferenceHandler thread
184 // is not running.
185 //
186 // This code is called on every object found by AOTArtifactFinder. When dumping the
187 // preimage archive, AOTArtifactFinder should not find any Reference objects.
188 precond(!CDSConfig::is_dumping_preimage_static_archive());
|
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "cds/aotReferenceObjSupport.hpp"
26 #include "cds/heapShared.hpp"
27 #include "classfile/javaClasses.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "classfile/systemDictionary.hpp"
30 #include "classfile/vmSymbols.hpp"
31 #include "logging/log.hpp"
32 #include "memory/resourceArea.hpp"
33 #include "memory/universe.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "oops/oopCast.inline.hpp"
36 #include "oops/oopHandle.inline.hpp"
37 #include "runtime/fieldDescriptor.inline.hpp"
38 #include "runtime/javaCalls.hpp"
39 #include "utilities/hashTable.hpp"
40
41 // Handling of java.lang.ref.Reference objects in the AOT cache
42 // ============================================================
43 //
44 // When AOTArtifactFinder finds an oop which is a instance of java.lang.ref.Reference:
45 //
46 // - We check if the oop is eligible to be stored in the AOT cache. If not, the AOT cache
47 // creation fails -- see AOTReferenceObjSupport::check_if_ref_obj()
48 //
49 // - Otherwise, we store the oop into the AOT cache, but we unconditionally reset its
50 // "next" and "discovered" fields to null. Otherwise, if AOTArtifactFinder follows these
51 // fields, it may found unrelated objects that we don't intend to cache.
52 //
53 // Eligibility
54 // ===========
55 //
147 {
148 Symbol* cds_name = vmSymbols::jdk_internal_misc_CDS();
149 Klass* cds_klass = SystemDictionary::resolve_or_fail(cds_name, true /*throw error*/, CHECK);
150 TempNewSymbol method_name = SymbolTable::new_symbol("getKeepAliveObjects");
151 TempNewSymbol method_sig = SymbolTable::new_symbol("()[Ljava/lang/Object;");
152 JavaValue result(T_OBJECT);
153 JavaCalls::call_static(&result, cds_klass, method_name, method_sig, CHECK);
154
155 _keep_alive_objs_array = OopHandle(Universe::vm_global(), result.get_oop());
156 }
157
158 // Trigger a GC to prune eligible referents that were not kept alive
159 Universe::heap()->collect(GCCause::_java_lang_system_gc);
160 }
161 }
162
163 void AOTReferenceObjSupport::init_keep_alive_objs_table() {
164 assert_at_safepoint(); // _keep_alive_objs_table uses raw oops
165 oop a = _keep_alive_objs_array.resolve();
166 if (a != nullptr) {
167 precond(a->is_refArray());
168 precond(AOTReferenceObjSupport::is_enabled());
169 refArrayOop array = oop_cast<refArrayOop>(a);
170
171 _keep_alive_objs_table = new (mtClass)KeepAliveObjectsTable();
172 for (int i = 0; i < array->length(); i++) {
173 oop obj = array->obj_at(i);
174 _keep_alive_objs_table->put(obj, true); // The array may have duplicated entries but that's OK.
175 }
176 }
177 }
178
179 // Returns true IFF obj is an instance of java.lang.ref.Reference. If so, perform extra eligibility checks.
180 bool AOTReferenceObjSupport::check_if_ref_obj(oop obj) {
181 assert_at_safepoint(); // _keep_alive_objs_table uses raw oops
182
183 if (obj->klass()->is_subclass_of(vmClasses::Reference_klass())) {
184 // The following check works only if the java.lang.ref.Reference$ReferenceHandler thread
185 // is not running.
186 //
187 // This code is called on every object found by AOTArtifactFinder. When dumping the
188 // preimage archive, AOTArtifactFinder should not find any Reference objects.
189 precond(!CDSConfig::is_dumping_preimage_static_archive());
|