src/hotspot/share/jfr/leakprofiler/checkpoint/objectSampleCheckpoint.cpp
changeset 57644 446dcfc2a925
parent 55571 49102ba8cf14
child 58132 caa25ab47aca
child 58154 060d9d139109
equal deleted inserted replaced
57643:5dae3de0e04b 57644:446dcfc2a925
   179   int count() const {
   179   int count() const {
   180     return _count;
   180     return _count;
   181   }
   181   }
   182 };
   182 };
   183 
   183 
   184 void ObjectSampleCheckpoint::install(JfrCheckpointWriter& writer, bool class_unload) {
   184 void ObjectSampleCheckpoint::install(JfrCheckpointWriter& writer, bool class_unload, bool type_set) {
   185   if (!writer.has_data()) {
   185   if (!writer.has_data()) {
   186     return;
   186     return;
   187   }
   187   }
   188 
   188 
   189   assert(writer.has_data(), "invariant");
   189   assert(writer.has_data(), "invariant");
   190   const JfrCheckpointBlobHandle h_cp = writer.checkpoint_blob();
   190   const JfrCheckpointBlobHandle h_cp = writer.checkpoint_blob();
       
   191   CheckpointInstall install(h_cp);
   191 
   192 
   192   // Class unload implies a safepoint.
   193   // Class unload implies a safepoint.
   193   // Not class unload implies the object sampler is locked, because it was claimed exclusively earlier.
   194   // Not class unload implies the object sampler is locked, because it was claimed exclusively earlier.
   194   // Therefore: direct access the object sampler instance is safe.
   195   // Therefore: direct access the object sampler instance is safe.
   195   const ObjectSampler* const object_sampler = ObjectSampler::sampler();
   196   ObjectSampler* const object_sampler = ObjectSampler::sampler();
   196   assert(object_sampler != NULL, "invariant");
   197   assert(object_sampler != NULL, "invariant");
   197 
   198 
   198   ObjectSample* const last = const_cast<ObjectSample*>(object_sampler->last());
   199   ObjectSample* const last = const_cast<ObjectSample*>(object_sampler->last());
   199   const ObjectSample* const last_resolved = object_sampler->last_resolved();
   200   const ObjectSample* const last_resolved = object_sampler->last_resolved();
   200   CheckpointInstall install(h_cp);
   201 
   201 
   202   // install only to new samples since last resolved checkpoint
   202   if (class_unload) {
       
   203     // all samples need class unload information
       
   204     do_samples(last, NULL, install);
       
   205     return;
       
   206   }
       
   207 
       
   208   // only new samples since last resolved checkpoint
       
   209   if (last != last_resolved) {
   203   if (last != last_resolved) {
   210     do_samples(last, last_resolved, install);
   204     do_samples(last, last_resolved, install);
   211     const_cast<ObjectSampler*>(object_sampler)->set_last_resolved(last);
   205     if (class_unload) {
       
   206       return;
       
   207     }
       
   208     if (type_set) {
       
   209       object_sampler->set_last_resolved(last);
       
   210     }
   212   }
   211   }
   213 }
   212 }
   214 
   213 
   215 void ObjectSampleCheckpoint::write(ObjectSampler* sampler, EdgeStore* edge_store, bool emit_all, Thread* thread) {
   214 void ObjectSampleCheckpoint::write(ObjectSampler* sampler, EdgeStore* edge_store, bool emit_all, Thread* thread) {
   216   assert(sampler != NULL, "invariant");
   215   assert(sampler != NULL, "invariant");
   287   assert(count > 0, "invariant");
   286   assert(count > 0, "invariant");
   288   writer.write_count((u4)count, count_offset);
   287   writer.write_count((u4)count, count_offset);
   289   JfrStackTraceRepository::write_metadata(writer);
   288   JfrStackTraceRepository::write_metadata(writer);
   290 
   289 
   291   // install the stacktrace checkpoint information to the candidates
   290   // install the stacktrace checkpoint information to the candidates
   292   ObjectSampleCheckpoint::install(writer, false);
   291   ObjectSampleCheckpoint::install(writer, false, false);
   293   return true;
   292   return true;
   294 }
   293 }