< prev index next >

src/demo/share/jvmti/heapViewer/heapViewer.c

Print this page
rev 12879 : 8136556: Add the ability to perform static builds of MacOSX x64 binaries
Reviewed-by: ihse, bdelsart, gadams, lfoltan, rriggs, hseigel, twisti
   1 /*
   2  * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   3  *
   4  * Redistribution and use in source and binary forms, with or without
   5  * modification, are permitted provided that the following conditions
   6  * are met:
   7  *
   8  *   - Redistributions of source code must retain the above copyright
   9  *     notice, this list of conditions and the following disclaimer.
  10  *
  11  *   - Redistributions in binary form must reproduce the above copyright
  12  *     notice, this list of conditions and the following disclaimer in the
  13  *     documentation and/or other materials provided with the distribution.
  14  *
  15  *   - Neither the name of Oracle nor the names of its
  16  *     contributors may be used to endorse or promote products derived
  17  *     from this software without specific prior written permission.
  18  *
  19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR


 218     jvmtiError          err;
 219 
 220     /* Make sure everything has been garbage collected */
 221     err = (*jvmti)->ForceGarbageCollection(jvmti);
 222     check_jvmti_error(jvmti, err, "force garbage collection");
 223 
 224     /* Disable events and dump the heap information */
 225     enterAgentMonitor(jvmti); {
 226         err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE,
 227                             JVMTI_EVENT_DATA_DUMP_REQUEST, NULL);
 228         check_jvmti_error(jvmti, err, "set event notification");
 229 
 230         dataDumpRequest(jvmti);
 231 
 232         gdata->vmDeathCalled = JNI_TRUE;
 233     } exitAgentMonitor(jvmti);
 234 }
 235 
 236 /* Agent_OnLoad() is called first, we prepare for a VM_INIT event here. */
 237 JNIEXPORT jint JNICALL
 238 Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
 239 {
 240     jint                rc;
 241     jvmtiError          err;
 242     jvmtiCapabilities   capabilities;
 243     jvmtiEventCallbacks callbacks;
 244     jvmtiEnv           *jvmti;
 245 
 246     /* Get JVMTI environment */
 247     jvmti = NULL;
 248     rc = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION);
 249     if (rc != JNI_OK) {
 250         fatal_error("ERROR: Unable to create jvmtiEnv, error=%d\n", rc);
 251         return -1;
 252     }
 253     if ( jvmti == NULL ) {
 254         fatal_error("ERROR: No jvmtiEnv* returned from GetEnv\n");
 255     }
 256 
 257     /* Get/Add JVMTI capabilities */
 258     (void)memset(&capabilities, 0, sizeof(capabilities));


 266     check_jvmti_error(jvmti, err, "create raw monitor");
 267 
 268     /* Set callbacks and enable event notifications */
 269     memset(&callbacks, 0, sizeof(callbacks));
 270     callbacks.VMInit                  = &vmInit;
 271     callbacks.VMDeath                 = &vmDeath;
 272     callbacks.DataDumpRequest         = &dataDumpRequest;
 273     err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks));
 274     check_jvmti_error(jvmti, err, "set event callbacks");
 275     err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
 276                         JVMTI_EVENT_VM_INIT, NULL);
 277     check_jvmti_error(jvmti, err, "set event notifications");
 278     err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
 279                         JVMTI_EVENT_VM_DEATH, NULL);
 280     check_jvmti_error(jvmti, err, "set event notifications");
 281     return 0;
 282 }
 283 
 284 /* Agent_OnUnload() is called last */
 285 JNIEXPORT void JNICALL
 286 Agent_OnUnload(JavaVM *vm)
 287 {
 288 }
   1 /*
   2  * Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
   3  *
   4  * Redistribution and use in source and binary forms, with or without
   5  * modification, are permitted provided that the following conditions
   6  * are met:
   7  *
   8  *   - Redistributions of source code must retain the above copyright
   9  *     notice, this list of conditions and the following disclaimer.
  10  *
  11  *   - Redistributions in binary form must reproduce the above copyright
  12  *     notice, this list of conditions and the following disclaimer in the
  13  *     documentation and/or other materials provided with the distribution.
  14  *
  15  *   - Neither the name of Oracle nor the names of its
  16  *     contributors may be used to endorse or promote products derived
  17  *     from this software without specific prior written permission.
  18  *
  19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR


 218     jvmtiError          err;
 219 
 220     /* Make sure everything has been garbage collected */
 221     err = (*jvmti)->ForceGarbageCollection(jvmti);
 222     check_jvmti_error(jvmti, err, "force garbage collection");
 223 
 224     /* Disable events and dump the heap information */
 225     enterAgentMonitor(jvmti); {
 226         err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_DISABLE,
 227                             JVMTI_EVENT_DATA_DUMP_REQUEST, NULL);
 228         check_jvmti_error(jvmti, err, "set event notification");
 229 
 230         dataDumpRequest(jvmti);
 231 
 232         gdata->vmDeathCalled = JNI_TRUE;
 233     } exitAgentMonitor(jvmti);
 234 }
 235 
 236 /* Agent_OnLoad() is called first, we prepare for a VM_INIT event here. */
 237 JNIEXPORT jint JNICALL
 238 DEF_Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
 239 {
 240     jint                rc;
 241     jvmtiError          err;
 242     jvmtiCapabilities   capabilities;
 243     jvmtiEventCallbacks callbacks;
 244     jvmtiEnv           *jvmti;
 245 
 246     /* Get JVMTI environment */
 247     jvmti = NULL;
 248     rc = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION);
 249     if (rc != JNI_OK) {
 250         fatal_error("ERROR: Unable to create jvmtiEnv, error=%d\n", rc);
 251         return -1;
 252     }
 253     if ( jvmti == NULL ) {
 254         fatal_error("ERROR: No jvmtiEnv* returned from GetEnv\n");
 255     }
 256 
 257     /* Get/Add JVMTI capabilities */
 258     (void)memset(&capabilities, 0, sizeof(capabilities));


 266     check_jvmti_error(jvmti, err, "create raw monitor");
 267 
 268     /* Set callbacks and enable event notifications */
 269     memset(&callbacks, 0, sizeof(callbacks));
 270     callbacks.VMInit                  = &vmInit;
 271     callbacks.VMDeath                 = &vmDeath;
 272     callbacks.DataDumpRequest         = &dataDumpRequest;
 273     err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks));
 274     check_jvmti_error(jvmti, err, "set event callbacks");
 275     err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
 276                         JVMTI_EVENT_VM_INIT, NULL);
 277     check_jvmti_error(jvmti, err, "set event notifications");
 278     err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
 279                         JVMTI_EVENT_VM_DEATH, NULL);
 280     check_jvmti_error(jvmti, err, "set event notifications");
 281     return 0;
 282 }
 283 
 284 /* Agent_OnUnload() is called last */
 285 JNIEXPORT void JNICALL
 286 DEF_Agent_OnUnload(JavaVM *vm)
 287 {
 288 }
< prev index next >