hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp
changeset 1894 5c343868d071
parent 1 489c9b5090e2
child 2131 98f9cef66a34
child 2138 a88fa6fb3834
child 2105 347008ce7984
equal deleted inserted replaced
1893:c82e388e17c5 1894:5c343868d071
  1228   constantPoolHandle old_cp(THREAD, the_class->constants());
  1228   constantPoolHandle old_cp(THREAD, the_class->constants());
  1229   constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  1229   constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  1230 
  1230 
  1231   // Constant pools are not easily reused so we allocate a new one
  1231   // Constant pools are not easily reused so we allocate a new one
  1232   // each time.
  1232   // each time.
       
  1233   // merge_cp is created unsafe for concurrent GC processing.  It
       
  1234   // should be marked safe before discarding it because, even if
       
  1235   // garbage.  If it crosses a card boundary, it may be scanned
       
  1236   // in order to find the start of the first complete object on the card.
  1233   constantPoolHandle merge_cp(THREAD,
  1237   constantPoolHandle merge_cp(THREAD,
  1234     oopFactory::new_constantPool(merge_cp_length, THREAD));
  1238     oopFactory::new_constantPool(merge_cp_length,
       
  1239                                  methodOopDesc::IsUnsafeConc,
       
  1240                                  THREAD));
  1235   int orig_length = old_cp->orig_length();
  1241   int orig_length = old_cp->orig_length();
  1236   if (orig_length == 0) {
  1242   if (orig_length == 0) {
  1237     // This old_cp is an actual original constant pool. We save
  1243     // This old_cp is an actual original constant pool. We save
  1238     // the original length in the merged constant pool so that
  1244     // the original length in the merged constant pool so that
  1239     // merge_constant_pools() can be more efficient. If a constant
  1245     // merge_constant_pools() can be more efficient. If a constant
  1272       // constant pool has not gone through link resolution nor have
  1278       // constant pool has not gone through link resolution nor have
  1273       // the new class bytecodes gone through constant pool cache
  1279       // the new class bytecodes gone through constant pool cache
  1274       // rewriting so we can't use the old constant pool with the new
  1280       // rewriting so we can't use the old constant pool with the new
  1275       // class.
  1281       // class.
  1276 
  1282 
       
  1283       merge_cp()->set_is_conc_safe(true);
  1277       merge_cp = constantPoolHandle();  // toss the merged constant pool
  1284       merge_cp = constantPoolHandle();  // toss the merged constant pool
  1278     } else if (old_cp->length() < scratch_cp->length()) {
  1285     } else if (old_cp->length() < scratch_cp->length()) {
  1279       // The old constant pool has fewer entries than the new constant
  1286       // The old constant pool has fewer entries than the new constant
  1280       // pool and the index map is empty. This means the new constant
  1287       // pool and the index map is empty. This means the new constant
  1281       // pool is a superset of the old constant pool. However, the old
  1288       // pool is a superset of the old constant pool. However, the old
  1282       // class bytecodes have already gone through constant pool cache
  1289       // class bytecodes have already gone through constant pool cache
  1283       // rewriting so we can't use the new constant pool with the old
  1290       // rewriting so we can't use the new constant pool with the old
  1284       // class.
  1291       // class.
  1285 
  1292 
       
  1293       merge_cp()->set_is_conc_safe(true);
  1286       merge_cp = constantPoolHandle();  // toss the merged constant pool
  1294       merge_cp = constantPoolHandle();  // toss the merged constant pool
  1287     } else {
  1295     } else {
  1288       // The old constant pool has more entries than the new constant
  1296       // The old constant pool has more entries than the new constant
  1289       // pool and the index map is empty. This means that both the old
  1297       // pool and the index map is empty. This means that both the old
  1290       // and merged constant pools are supersets of the new constant
  1298       // and merged constant pools are supersets of the new constant
  1294       // merged constant pool; the previous new constant pool will
  1302       // merged constant pool; the previous new constant pool will
  1295       // get GCed.
  1303       // get GCed.
  1296       set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  1304       set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  1297         THREAD);
  1305         THREAD);
  1298       // drop local ref to the merged constant pool
  1306       // drop local ref to the merged constant pool
       
  1307       merge_cp()->set_is_conc_safe(true);
  1299       merge_cp = constantPoolHandle();
  1308       merge_cp = constantPoolHandle();
  1300     }
  1309     }
  1301   } else {
  1310   } else {
  1302     if (RC_TRACE_ENABLED(0x00040000)) {
  1311     if (RC_TRACE_ENABLED(0x00040000)) {
  1303       // don't want to loop unless we are tracing
  1312       // don't want to loop unless we are tracing
  1323     // merged constant pool so now the rewritten bytecodes have
  1332     // merged constant pool so now the rewritten bytecodes have
  1324     // valid references; the previous new constant pool will get
  1333     // valid references; the previous new constant pool will get
  1325     // GCed.
  1334     // GCed.
  1326     set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  1335     set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  1327       THREAD);
  1336       THREAD);
  1328   }
  1337     merge_cp()->set_is_conc_safe(true);
       
  1338   }
       
  1339   assert(old_cp()->is_conc_safe(), "Just checking");
       
  1340   assert(scratch_cp()->is_conc_safe(), "Just checking");
  1329 
  1341 
  1330   return JVMTI_ERROR_NONE;
  1342   return JVMTI_ERROR_NONE;
  1331 } // end merge_cp_and_rewrite()
  1343 } // end merge_cp_and_rewrite()
  1332 
  1344 
  1333 
  1345 
  2312   if (shrink) {
  2324   if (shrink) {
  2313     // scratch_cp is a merged constant pool and has enough space for a
  2325     // scratch_cp is a merged constant pool and has enough space for a
  2314     // worst case merge situation. We want to associate the minimum
  2326     // worst case merge situation. We want to associate the minimum
  2315     // sized constant pool with the klass to save space.
  2327     // sized constant pool with the klass to save space.
  2316     constantPoolHandle smaller_cp(THREAD,
  2328     constantPoolHandle smaller_cp(THREAD,
  2317       oopFactory::new_constantPool(scratch_cp_length, THREAD));
  2329       oopFactory::new_constantPool(scratch_cp_length,
       
  2330                                    methodOopDesc::IsUnsafeConc,
       
  2331                                    THREAD));
  2318     // preserve orig_length() value in the smaller copy
  2332     // preserve orig_length() value in the smaller copy
  2319     int orig_length = scratch_cp->orig_length();
  2333     int orig_length = scratch_cp->orig_length();
  2320     assert(orig_length != 0, "sanity check");
  2334     assert(orig_length != 0, "sanity check");
  2321     smaller_cp->set_orig_length(orig_length);
  2335     smaller_cp->set_orig_length(orig_length);
  2322     scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  2336     scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  2323     scratch_cp = smaller_cp;
  2337     scratch_cp = smaller_cp;
       
  2338     smaller_cp()->set_is_conc_safe(true);
  2324   }
  2339   }
  2325 
  2340 
  2326   // attach new constant pool to klass
  2341   // attach new constant pool to klass
  2327   scratch_cp->set_pool_holder(scratch_class());
  2342   scratch_cp->set_pool_holder(scratch_class());
  2328 
  2343 
  2514       } // end for each local variable table entry
  2529       } // end for each local variable table entry
  2515     } // end if there are local variable table entries
  2530     } // end if there are local variable table entries
  2516 
  2531 
  2517     rewrite_cp_refs_in_stack_map_table(method, THREAD);
  2532     rewrite_cp_refs_in_stack_map_table(method, THREAD);
  2518   } // end for each method
  2533   } // end for each method
       
  2534   assert(scratch_cp()->is_conc_safe(), "Just checking");
  2519 } // end set_new_constant_pool()
  2535 } // end set_new_constant_pool()
  2520 
  2536 
  2521 
  2537 
  2522 // Unevolving classes may point to methods of the_class directly
  2538 // Unevolving classes may point to methods of the_class directly
  2523 // from their constant pool caches, itables, and/or vtables. We
  2539 // from their constant pool caches, itables, and/or vtables. We