Add field access & modify JVMTI callbacks
This adds support for the FieldAccess and FieldModification callbacks
in JVMTI and all other functions and behaviors associated with the
can_generate_field_modification_events and
can_generate_field_access_events capabilities.
Tests follow in the next CL.
Bug: 34409228
Test: ./test.py --host -j40
Change-Id: Id18fc53677cc1f96e1460c498ade7607219d5a79
diff --git a/runtime/openjdkjvmti/art_jvmti.h b/runtime/openjdkjvmti/art_jvmti.h
index 369b2d7..8ba3527 100644
--- a/runtime/openjdkjvmti/art_jvmti.h
+++ b/runtime/openjdkjvmti/art_jvmti.h
@@ -34,6 +34,7 @@
#include <memory>
#include <type_traits>
+#include <unordered_set>
#include <jni.h>
@@ -46,6 +47,10 @@
#include "jni_env_ext.h"
#include "jvmti.h"
+namespace art {
+class ArtField;
+}
+
namespace openjdkjvmti {
class ObjectTagTable;
@@ -62,6 +67,15 @@
// Tagging is specific to the jvmtiEnv.
std::unique_ptr<ObjectTagTable> object_tag_table;
+ // Set of watched fields is unique to each jvmtiEnv.
+ // TODO It might be good to follow the RI and only let one jvmtiEnv ever have the watch caps so
+ // we can record this on the field directly. We could do this either using free access-flag bits
+ // or by putting a list in the ClassExt of a field's DeclaringClass.
+ // TODO Maybe just have an extension to let one put a watch on every field, that would probably be
+ // good enough maybe since you probably want either a few or all/almost all of them.
+ std::unordered_set<art::ArtField*> access_watched_fields;
+ std::unordered_set<art::ArtField*> modify_watched_fields;
+
ArtJvmTiEnv(art::JavaVMExt* runtime, EventHandler* event_handler);
static ArtJvmTiEnv* AsArtJvmTiEnv(jvmtiEnv* env) {
@@ -194,8 +208,8 @@
const jvmtiCapabilities kPotentialCapabilities = {
.can_tag_objects = 1,
- .can_generate_field_modification_events = 0,
- .can_generate_field_access_events = 0,
+ .can_generate_field_modification_events = 1,
+ .can_generate_field_access_events = 1,
.can_get_bytecodes = 0,
.can_get_synthetic_attribute = 1,
.can_get_owned_monitor_info = 0,