< prev index next >

src/share/vm/jfr/writers/jfrJavaEventWriter.cpp

Print this page
rev 9061 : 8227011: Starting a JFR recording in response to JVMTI VMInit and / or Java agent premain corrupts memory
Reviewed-by: egahlin, rwestberg


 125 
 126   const char valid_name[] = "valid";
 127   Symbol* const valid_sym = SymbolTable::lookup(valid_name, sizeof valid_name - 1, CHECK_false);
 128   assert (valid_sym != NULL, "invariant");
 129   assert(invalid_offset == valid_offset, "invariant");
 130   compute_offset(valid_offset, klass, valid_sym, vmSymbols::bool_signature());
 131   assert(valid_offset != invalid_offset, "invariant");
 132   return true;
 133 }
 134 
 135 bool JfrJavaEventWriter::has_required_classes(TRAPS) {
 136   const char class_name[] = "jdk/jfr/internal/EventWriter";
 137   Symbol* const k_sym = SymbolTable::lookup(class_name, sizeof class_name - 1, CHECK_false);
 138   Klass* klass = SystemDictionary::resolve_or_null(k_sym, CHECK_false);
 139   return (klass != NULL);
 140 }
 141 
 142 bool JfrJavaEventWriter::initialize() {
 143   static bool initialized = false;
 144   if (!initialized) {
 145     Thread* thread = Thread::current();
 146     initialized = setup_event_writer_offsets(thread);
 147   }
 148   return initialized;
 149 }
 150 
 151 jboolean JfrJavaEventWriter::flush(jobject writer, jint used, jint requested, JavaThread* jt) {
 152   DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(jt));
 153   assert(writer != NULL, "invariant");
 154   oop const w = JNIHandles::resolve_non_null(writer);
 155   assert(w != NULL, "invariant");
 156   JfrBuffer* const current = jt->jfr_thread_local()->java_buffer();
 157   assert(current != NULL, "invariant");
 158   JfrBuffer* const buffer = JfrStorage::flush(current, used, requested, false, jt);
 159   assert(buffer != NULL, "invariant");
 160   // "validity" is contextually defined here to mean
 161   // that some memory location was provided that is
 162   // large enough to accommodate the "requested size".
 163   const bool is_valid = buffer->free_size() >= (size_t)(used + requested);
 164   u1* const new_current_position = is_valid ? buffer->pos() + used : buffer->pos();

 165   w->long_field_put(start_pos_offset, (jlong)buffer->pos());
 166   w->long_field_put(current_pos_offset, (jlong)new_current_position);
 167   // only update java writer if underlying memory changed
 168   if (buffer != current) {
 169     w->long_field_put(start_pos_address_offset, (jlong)buffer->pos_address());
 170     w->long_field_put(max_pos_offset, (jlong)buffer->end());
 171   }
 172   if (!is_valid) {
 173     // mark writer as invalid for this write attempt
 174     w->release_bool_field_put(valid_offset, JNI_FALSE);
 175     return JNI_FALSE;
 176   }
 177   // An exclusive use of a leased buffer is treated equivalent to
 178   // holding a system resource. As such, it should be released as soon as possible.
 179   // Returning true here signals that the thread will need to call flush again
 180   // on EventWriter.endEvent() and that flush will return the lease.
 181   return buffer->lease() ? JNI_TRUE : JNI_FALSE;
 182 }
 183 
 184 class JfrJavaEventWriterNotificationClosure : public ThreadClosure {




 125 
 126   const char valid_name[] = "valid";
 127   Symbol* const valid_sym = SymbolTable::lookup(valid_name, sizeof valid_name - 1, CHECK_false);
 128   assert (valid_sym != NULL, "invariant");
 129   assert(invalid_offset == valid_offset, "invariant");
 130   compute_offset(valid_offset, klass, valid_sym, vmSymbols::bool_signature());
 131   assert(valid_offset != invalid_offset, "invariant");
 132   return true;
 133 }
 134 
 135 bool JfrJavaEventWriter::has_required_classes(TRAPS) {
 136   const char class_name[] = "jdk/jfr/internal/EventWriter";
 137   Symbol* const k_sym = SymbolTable::lookup(class_name, sizeof class_name - 1, CHECK_false);
 138   Klass* klass = SystemDictionary::resolve_or_null(k_sym, CHECK_false);
 139   return (klass != NULL);
 140 }
 141 
 142 bool JfrJavaEventWriter::initialize() {
 143   static bool initialized = false;
 144   if (!initialized) {
 145     initialized = setup_event_writer_offsets(Thread::current());

 146   }
 147   return initialized;
 148 }
 149 
 150 jboolean JfrJavaEventWriter::flush(jobject writer, jint used, jint requested, JavaThread* jt) {
 151   DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(jt));
 152   assert(writer != NULL, "invariant");
 153   oop const w = JNIHandles::resolve_non_null(writer);
 154   assert(w != NULL, "invariant");
 155   JfrBuffer* const current = jt->jfr_thread_local()->java_buffer();
 156   assert(current != NULL, "invariant");
 157   JfrBuffer* const buffer = JfrStorage::flush(current, used, requested, false, jt);
 158   assert(buffer != NULL, "invariant");
 159   // "validity" is contextually defined here to mean
 160   // that some memory location was provided that is
 161   // large enough to accommodate the "requested size".
 162   const bool is_valid = buffer->free_size() >= (size_t)(used + requested);
 163   u1* const new_current_position = is_valid ? buffer->pos() + used : buffer->pos();
 164   assert(start_pos_offset != invalid_offset, "invariant");
 165   w->long_field_put(start_pos_offset, (jlong)buffer->pos());
 166   w->long_field_put(current_pos_offset, (jlong)new_current_position);
 167   // only update java writer if underlying memory changed
 168   if (buffer != current) {
 169     w->long_field_put(start_pos_address_offset, (jlong)buffer->pos_address());
 170     w->long_field_put(max_pos_offset, (jlong)buffer->end());
 171   }
 172   if (!is_valid) {
 173     // mark writer as invalid for this write attempt
 174     w->release_bool_field_put(valid_offset, JNI_FALSE);
 175     return JNI_FALSE;
 176   }
 177   // An exclusive use of a leased buffer is treated equivalent to
 178   // holding a system resource. As such, it should be released as soon as possible.
 179   // Returning true here signals that the thread will need to call flush again
 180   // on EventWriter.endEvent() and that flush will return the lease.
 181   return buffer->lease() ? JNI_TRUE : JNI_FALSE;
 182 }
 183 
 184 class JfrJavaEventWriterNotificationClosure : public ThreadClosure {


< prev index next >