0

Below is the demo code():

/* Typedef to hold class details */
typedef struct {
     char *signature;
     int   count;
     int   space;
 } ClassDetails;
 ....
/* Tag this jclass */
err = (*jvmti)->SetTag(jvmti, classes[i], (jlong)(ptrdiff_t)(void*)(&details[i]));

the prototype of SetTag is jvmtiError SetTag(jvmtiEnv* env, jobject object, jlong tag).

Can I just use it like this: err = (*jvmti)->SetTag(jvmti, classes[i], (jlong)(&details[i])); ?

Ridox
  • 1,073
  • 13
  • 18

1 Answers1

0

When using a tag that is a pointer, use a cast to ptrdiff_t(Standard C typedef for an integer that holds a pointer difference) to avoid compiler warnings and errors. Never use int or long, you'll find out that int and long are not always big enough to hold a pointer, truncating your address, where ptrdiff_t will always be big enough to hold all the bits of a pointer. Detailed info is here JVMPI transition to JVMTI

Ridox
  • 1,073
  • 13
  • 18