< prev index next >

src/demo/share/jvmti/mtrace/mtrace.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


 680             }
 681             /* Add this item to the list */
 682             next = get_token(next, ",=", gdata->exclude+used, maxlen);
 683             /* Check for token scan error */
 684             if ( next==NULL ) {
 685                 fatal_error("ERROR: exclude option error\n");
 686             }
 687         } else if ( token[0]!=0 ) {
 688             /* We got a non-empty token and we don't know what it is. */
 689             fatal_error("ERROR: Unknown option: %s\n", token);
 690         }
 691         /* Get the next token (returns NULL if there are no more) */
 692         next = get_token(next, ",=", token, sizeof(token));
 693     }
 694 }
 695 
 696 /* Agent_OnLoad: This is called immediately after the shared library is
 697  *   loaded. This is the first code executed.
 698  */
 699 JNIEXPORT jint JNICALL
 700 Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
 701 {
 702     static GlobalAgentData data;
 703     jvmtiEnv              *jvmti;
 704     jvmtiError             error;
 705     jint                   res;
 706     jvmtiCapabilities      capabilities;
 707     jvmtiEventCallbacks    callbacks;
 708 
 709     /* Setup initial global agent data area
 710      *   Use of static/extern data should be handled carefully here.
 711      *   We need to make sure that we are able to cleanup after ourselves
 712      *     so anything allocated in this library needs to be freed in
 713      *     the Agent_OnUnload() function.
 714      */
 715     (void)memset((void*)&data, 0, sizeof(data));
 716     gdata = &data;
 717 
 718     /* First thing we need to do is get the jvmtiEnv* or JVMTI environment */
 719     res = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1);
 720     if (res != JNI_OK) {


 778                           JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, (jthread)NULL);
 779     check_jvmti_error(jvmti, error, "Cannot set event notification");
 780 
 781     /* Here we create a raw monitor for our use in this agent to
 782      *   protect critical sections of code.
 783      */
 784     error = (*jvmti)->CreateRawMonitor(jvmti, "agent data", &(gdata->lock));
 785     check_jvmti_error(jvmti, error, "Cannot create raw monitor");
 786 
 787     /* Add demo jar file to boot classpath */
 788     add_demo_jar_to_bootclasspath(jvmti, "mtrace");
 789 
 790     /* We return JNI_OK to signify success */
 791     return JNI_OK;
 792 }
 793 
 794 /* Agent_OnUnload: This is called immediately before the shared library is
 795  *   unloaded. This is the last code executed.
 796  */
 797 JNIEXPORT void JNICALL
 798 Agent_OnUnload(JavaVM *vm)
 799 {
 800     /* Make sure all malloc/calloc/strdup space is freed */
 801     if ( gdata->include != NULL ) {
 802         (void)free((void*)gdata->include);
 803         gdata->include = NULL;
 804     }
 805     if ( gdata->exclude != NULL ) {
 806         (void)free((void*)gdata->exclude);
 807         gdata->exclude = NULL;
 808     }
 809     if ( gdata->classes != NULL ) {
 810         int cnum;
 811 
 812         for ( cnum = 0 ; cnum < gdata->ccount ; cnum++ ) {
 813             ClassInfo *cp;
 814 
 815             cp = gdata->classes + cnum;
 816             (void)free((void*)cp->name);
 817             if ( cp->mcount > 0 ) {
 818                 int mnum;
   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


 680             }
 681             /* Add this item to the list */
 682             next = get_token(next, ",=", gdata->exclude+used, maxlen);
 683             /* Check for token scan error */
 684             if ( next==NULL ) {
 685                 fatal_error("ERROR: exclude option error\n");
 686             }
 687         } else if ( token[0]!=0 ) {
 688             /* We got a non-empty token and we don't know what it is. */
 689             fatal_error("ERROR: Unknown option: %s\n", token);
 690         }
 691         /* Get the next token (returns NULL if there are no more) */
 692         next = get_token(next, ",=", token, sizeof(token));
 693     }
 694 }
 695 
 696 /* Agent_OnLoad: This is called immediately after the shared library is
 697  *   loaded. This is the first code executed.
 698  */
 699 JNIEXPORT jint JNICALL
 700 DEF_Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
 701 {
 702     static GlobalAgentData data;
 703     jvmtiEnv              *jvmti;
 704     jvmtiError             error;
 705     jint                   res;
 706     jvmtiCapabilities      capabilities;
 707     jvmtiEventCallbacks    callbacks;
 708 
 709     /* Setup initial global agent data area
 710      *   Use of static/extern data should be handled carefully here.
 711      *   We need to make sure that we are able to cleanup after ourselves
 712      *     so anything allocated in this library needs to be freed in
 713      *     the Agent_OnUnload() function.
 714      */
 715     (void)memset((void*)&data, 0, sizeof(data));
 716     gdata = &data;
 717 
 718     /* First thing we need to do is get the jvmtiEnv* or JVMTI environment */
 719     res = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1);
 720     if (res != JNI_OK) {


 778                           JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, (jthread)NULL);
 779     check_jvmti_error(jvmti, error, "Cannot set event notification");
 780 
 781     /* Here we create a raw monitor for our use in this agent to
 782      *   protect critical sections of code.
 783      */
 784     error = (*jvmti)->CreateRawMonitor(jvmti, "agent data", &(gdata->lock));
 785     check_jvmti_error(jvmti, error, "Cannot create raw monitor");
 786 
 787     /* Add demo jar file to boot classpath */
 788     add_demo_jar_to_bootclasspath(jvmti, "mtrace");
 789 
 790     /* We return JNI_OK to signify success */
 791     return JNI_OK;
 792 }
 793 
 794 /* Agent_OnUnload: This is called immediately before the shared library is
 795  *   unloaded. This is the last code executed.
 796  */
 797 JNIEXPORT void JNICALL
 798 DEF_Agent_OnUnload(JavaVM *vm)
 799 {
 800     /* Make sure all malloc/calloc/strdup space is freed */
 801     if ( gdata->include != NULL ) {
 802         (void)free((void*)gdata->include);
 803         gdata->include = NULL;
 804     }
 805     if ( gdata->exclude != NULL ) {
 806         (void)free((void*)gdata->exclude);
 807         gdata->exclude = NULL;
 808     }
 809     if ( gdata->classes != NULL ) {
 810         int cnum;
 811 
 812         for ( cnum = 0 ; cnum < gdata->ccount ; cnum++ ) {
 813             ClassInfo *cp;
 814 
 815             cp = gdata->classes + cnum;
 816             (void)free((void*)cp->name);
 817             if ( cp->mcount > 0 ) {
 818                 int mnum;
< prev index next >