title: Perplexed by jvmti object allocation callback behavior
body: <p>Can anybody explain to me why can I get a callback when jvm allocates some java objects, but not others?  Here is what I am doing:</p>
  
  <pre><code>static jvmtiCapabilities    capa;
  static jvmtiEnv*            jvmti                   = NULL;
  static const char*          fileName                = "C:\\temp\\ObjectInitCallbackDump.txt";
  static ofstream             outFileStream;
  
  void JNICALL callbackObjectAllocation ( jvmtiEnv*   jvmti_env, 
                                          JNIEnv*     jni_env,
                                          jthread     thread,
                                          jobject     object,
                                          jclass      object_klass,
                                          jlong       size            )
  {
      char*       generic_ptr_class;
      char*       class_name;
      jvmtiError  error;
  
      error = jvmti_env-&gt;GetClassSignature(object_klass, &amp;class_name, &amp;generic_ptr_class);
      if (check_jvmti_error(jvmti_env, error, "Failed to get class signature")) {
          return;
      }
      outFileStream &lt;&lt; class_name &lt;&lt; std::endl;
  }
  
  JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
      jint                result;
      jvmtiError          error;
      jvmtiEventCallbacks callbacks;
  
      outFileStream.open(fileName,ios::trunc);
  
      result  = jvm-&gt;GetEnv((void**) &amp;jvmti, JVMTI_VERSION_1_1);
      if (result != JNI_OK || jvmti == NULL) {
          printf("error\n");
          return JNI_ERR;
      } else {
          printf("loaded agent\n");
      }
  
      (void) memset(&amp;capa, 0, sizeof(jvmtiCapabilities));
      capa.can_generate_vm_object_alloc_events        = 1;
  
      error = jvmti-&gt;AddCapabilities(&amp;capa);
      if (check_jvmti_error(jvmti, error, "Unable to set capabilities") != JNI_OK) {
          return JNI_ERR;
      }
  
      (void) memset(&amp;callbacks, 0, sizeof(callbacks));
      callbacks.VMObjectAlloc         = &amp;callbackObjectAllocation;
  
      error = jvmti-&gt;SetEventCallbacks(&amp;callbacks, (jint) sizeof(callbacks));
      if (check_jvmti_error(jvmti, error, "Unable to set callbacks") != JNI_OK) {
          return JNI_ERR;
      }
  
      error = jvmti-&gt;SetEventNotificationMode(    JVMTI_ENABLE,
                                                  JVMTI_EVENT_VM_OBJECT_ALLOC,
                                                  (jthread) NULL);
      if (check_jvmti_error(jvmti, error,
              "Unable to set method entry notifications") != JNI_OK) {
          return JNI_ERR;
      }
  
      return JNI_OK;
  }
  
  JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm) {
      outFileStream.close();
  }
  </code></pre>
  
  <p>When I examine the file that I create, I do not see the classes that I am interested in, although I know they are there and NetBeans tells me there is exactly one instance of that class in the jvm.  Any thoughts???</p>
  
  <p>Nikita</p>