Add obsolete object event

Add an extension event to notify agents that an object is becoming
obsolete. This is meant to be used by agents performing allocation
tracking using the VMObjectAlloc event to let them know that an object
replacement is occurring. This event is only triggered by calls to
JVMTI functions that create obsolete objects. Normal GC actions
(including a moving compaction) will not cause this event to trigger.

Test: ./test.py --host
Bug: 134162467

Change-Id: If48b880814a751ba6c24c18d0ad116db4f8fdf64
diff --git a/openjdkjvmti/events-inl.h b/openjdkjvmti/events-inl.h
index 627129a..22822f8 100644
--- a/openjdkjvmti/events-inl.h
+++ b/openjdkjvmti/events-inl.h
@@ -123,7 +123,8 @@
   fn(GarbageCollectionFinish, ArtJvmtiEvent::kGarbageCollectionFinish)               \
   fn(ObjectFree,              ArtJvmtiEvent::kObjectFree)                            \
   fn(VMObjectAlloc,           ArtJvmtiEvent::kVmObjectAlloc)                         \
-  fn(DdmPublishChunk,         ArtJvmtiEvent::kDdmPublishChunk)
+  fn(DdmPublishChunk,         ArtJvmtiEvent::kDdmPublishChunk)                       \
+  fn(ObsoleteObjectCreated,   ArtJvmtiEvent::kObsoleteObjectCreated)
 
 template <ArtJvmtiEvent kEvent>
 struct EventFnType {
@@ -318,6 +319,24 @@
   }
 }
 
+template <>
+inline void EventHandler::DispatchEventOnEnv<ArtJvmtiEvent::kObsoleteObjectCreated>(
+    ArtJvmTiEnv* env, art::Thread* thread, jlong* obsolete_tag, jlong* new_tag) const {
+  static constexpr ArtJvmtiEvent kEvent = ArtJvmtiEvent::kObsoleteObjectCreated;
+  DCHECK(env != nullptr);
+  if (ShouldDispatch<kEvent>(env, thread, obsolete_tag, new_tag)) {
+    art::ScopedThreadStateChange stsc(thread, art::ThreadState::kNative);
+    impl::EventHandlerFunc<kEvent> func(env);
+    ExecuteCallback<kEvent>(func, obsolete_tag, new_tag);
+  } else {
+    // Unlike most others this has a default action to make sure that agents without knowledge of
+    // this extension get reasonable behavior.
+    jlong temp = *obsolete_tag;
+    *obsolete_tag = *new_tag;
+    *new_tag = temp;
+  }
+}
+
 template <ArtJvmtiEvent kEvent, typename ...Args>
 inline void EventHandler::ExecuteCallback(impl::EventHandlerFunc<kEvent> handler, Args... args) {
   handler.ExecuteCallback(args...);