248 if (_cache == NULL) {
249 return; // nothing to do
250 }
251
252 InstanceKlass *ik = pool_holder();
253 if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() ||
254 ik->is_shared_app_class())) {
255 // Archiving resolved references for classes from non-builtin loaders
256 // is not yet supported.
257 set_resolved_references(NULL);
258 return;
259 }
260
261 objArrayOop rr = resolved_references();
262 if (rr != NULL) {
263 for (int i = 0; i < rr->length(); i++) {
264 oop p = rr->obj_at(i);
265 if (p != NULL) {
266 int index = object_to_cp_index(i);
267 if (tag_at(index).is_string()) {
268 oop op = StringTable::archive_string(p, THREAD);
269 // If the String object is not archived (possibly too large),
270 // NULL is returned. Also set it in the array, so we won't
271 // have a 'bad' reference in the archived resolved_reference
272 // array.
273 rr->obj_at_put(i, op);
274 } else {
275 rr->obj_at_put(i, NULL);
276 }
277 }
278 }
279 oop archived = MetaspaceShared::archive_heap_object(rr, THREAD);
280 _cache->set_archived_references(archived);
281 set_resolved_references(NULL);
282 }
283 }
284 #endif
285
286 // CDS support. Create a new resolved_references array.
287 void ConstantPool::restore_unshareable_info(TRAPS) {
288 assert(is_constantPool(), "ensure C++ vtable is restored");
320 objArrayOop stom = oopFactory::new_objArray(SystemDictionary::Object_klass(), map_length, CHECK);
321 Handle refs_handle(THREAD, (oop)stom); // must handleize.
322 set_resolved_references(loader_data->add_handle(refs_handle));
323 }
324 }
325 }
326 }
327
328 void ConstantPool::remove_unshareable_info() {
329 // Resolved references are not in the shared archive.
330 // Save the length for restoration. It is not necessarily the same length
331 // as reference_map.length() if invokedynamic is saved. It is needed when
332 // re-creating the resolved reference array if archived heap data cannot be map
333 // at runtime.
334 set_resolved_reference_length(
335 resolved_references() != NULL ? resolved_references()->length() : 0);
336
337 // If archiving heap objects is not allowed, clear the resolved references.
338 // Otherwise, it is cleared after the resolved references array is cached
339 // (see archive_resolved_references()).
340 if (!MetaspaceShared::allow_archive_heap_object()) {
341 set_resolved_references(NULL);
342 }
343
344 // Shared ConstantPools are in the RO region, so the _flags cannot be modified.
345 // The _on_stack flag is used to prevent ConstantPools from deallocation during
346 // class redefinition. Since shared ConstantPools cannot be deallocated anyway,
347 // we always set _on_stack to true to avoid having to change _flags during runtime.
348 _flags |= (_on_stack | _is_shared);
349 }
350
351 int ConstantPool::cp_to_object_index(int cp_index) {
352 // this is harder don't do this so much.
353 int i = reference_map()->find(cp_index);
354 // We might not find the index for jsr292 call.
355 return (i < 0) ? _no_index_sentinel : i;
356 }
357
358 void ConstantPool::string_at_put(int which, int obj_index, oop str) {
359 resolved_references()->obj_at_put(obj_index, str);
360 }
|
248 if (_cache == NULL) {
249 return; // nothing to do
250 }
251
252 InstanceKlass *ik = pool_holder();
253 if (!(ik->is_shared_boot_class() || ik->is_shared_platform_class() ||
254 ik->is_shared_app_class())) {
255 // Archiving resolved references for classes from non-builtin loaders
256 // is not yet supported.
257 set_resolved_references(NULL);
258 return;
259 }
260
261 objArrayOop rr = resolved_references();
262 if (rr != NULL) {
263 for (int i = 0; i < rr->length(); i++) {
264 oop p = rr->obj_at(i);
265 if (p != NULL) {
266 int index = object_to_cp_index(i);
267 if (tag_at(index).is_string()) {
268 oop op = StringTable::create_archived_string(p, THREAD);
269 // If the String object is not archived (possibly too large),
270 // NULL is returned. Also set it in the array, so we won't
271 // have a 'bad' reference in the archived resolved_reference
272 // array.
273 rr->obj_at_put(i, op);
274 } else {
275 rr->obj_at_put(i, NULL);
276 }
277 }
278 }
279 oop archived = MetaspaceShared::archive_heap_object(rr, THREAD);
280 _cache->set_archived_references(archived);
281 set_resolved_references(NULL);
282 }
283 }
284 #endif
285
286 // CDS support. Create a new resolved_references array.
287 void ConstantPool::restore_unshareable_info(TRAPS) {
288 assert(is_constantPool(), "ensure C++ vtable is restored");
320 objArrayOop stom = oopFactory::new_objArray(SystemDictionary::Object_klass(), map_length, CHECK);
321 Handle refs_handle(THREAD, (oop)stom); // must handleize.
322 set_resolved_references(loader_data->add_handle(refs_handle));
323 }
324 }
325 }
326 }
327
328 void ConstantPool::remove_unshareable_info() {
329 // Resolved references are not in the shared archive.
330 // Save the length for restoration. It is not necessarily the same length
331 // as reference_map.length() if invokedynamic is saved. It is needed when
332 // re-creating the resolved reference array if archived heap data cannot be map
333 // at runtime.
334 set_resolved_reference_length(
335 resolved_references() != NULL ? resolved_references()->length() : 0);
336
337 // If archiving heap objects is not allowed, clear the resolved references.
338 // Otherwise, it is cleared after the resolved references array is cached
339 // (see archive_resolved_references()).
340 if (!MetaspaceShared::is_heap_object_archiving_allowed()) {
341 set_resolved_references(NULL);
342 }
343
344 // Shared ConstantPools are in the RO region, so the _flags cannot be modified.
345 // The _on_stack flag is used to prevent ConstantPools from deallocation during
346 // class redefinition. Since shared ConstantPools cannot be deallocated anyway,
347 // we always set _on_stack to true to avoid having to change _flags during runtime.
348 _flags |= (_on_stack | _is_shared);
349 }
350
351 int ConstantPool::cp_to_object_index(int cp_index) {
352 // this is harder don't do this so much.
353 int i = reference_map()->find(cp_index);
354 // We might not find the index for jsr292 call.
355 return (i < 0) ? _no_index_sentinel : i;
356 }
357
358 void ConstantPool::string_at_put(int which, int obj_index, oop str) {
359 resolved_references()->obj_at_put(obj_index, str);
360 }
|