1

I am trying to get the class name from jobject in jvmti, I tried get

(*jvmti)->GetClassSignature(jvmti, object_klass, &signature, &generic);

for code like this

public static void main(String arg[]) throws Exception {
    Set<String> names = new HashSet<>();
    names.add("foo");
    names.add("bar");
    System.out.println(names);
}

I am tracking all allocation of objects in jvmti, I don't get java.util.HashSet in this hook

I get bunch of

Ljava/lang/String;     Ljava/lang/Object;Ljava/io/Serializable;Ljava/lang/Comparable<Ljava/lang/String;>;Ljava/lang/CharSequence;
Ljava/lang/reflect/Method; (null)

and some other classes, but I don't see new HashSet<> initialization

user3833308
  • 1,132
  • 3
  • 14
  • 39

1 Answers1

3

I suppose you are trying VMObjectAlloc JVMTI notification. This notification is not sent for allocations made in Java code. This behaviour is described in JVMTI specification:

Sent when ... the allocation is not detectable by other intrumentation mechanisms. Generally object allocation should be detected by instrumenting the bytecodes of allocating methods.

...

Cases where this event would not be generated:

  • Allocation due to bytecodes - for example, the new and newarray VM instructions
  • Allocation due to JNI function calls - for example, AllocObject
  • Allocations during VM initialization
  • VM internal objects

This answer explains how to track object allocations in Java.

Community
  • 1
  • 1
apangin
  • 92,924
  • 10
  • 193
  • 247