< prev index next >

src/demo/share/jvmti/compiledMethodLoad/compiledMethodLoad.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) 2010, 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


 208         err = (*jvmti)->Deallocate(jvmti, (unsigned char*)name);
 209         check_jvmti_error(jvmti, err, "deallocate name");
 210     }
 211     if (signature != NULL) {
 212         err = (*jvmti)->Deallocate(jvmti, (unsigned char*)signature);
 213         check_jvmti_error(jvmti, err, "deallocate signature");
 214     }
 215     if (generic_ptr != NULL) {
 216         err = (*jvmti)->Deallocate(jvmti, (unsigned char*)generic_ptr);
 217         check_jvmti_error(jvmti, err, "deallocate generic_ptr");
 218     }
 219 
 220     err = (*jvmti)->RawMonitorExit(jvmti, lock);
 221     check_jvmti_error(jvmti, err, "raw monitor exit");
 222 }
 223 
 224 /* Agent_OnLoad() is called first, we prepare for a COMPILED_METHOD_LOAD
 225  * event here.
 226  */
 227 JNIEXPORT jint JNICALL
 228 Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
 229 {
 230     jint                rc;
 231     jvmtiError          err;
 232     jvmtiCapabilities   capabilities;
 233     jvmtiEventCallbacks callbacks;
 234 
 235     fp = fopen(OUTPUT_FILE, "w");
 236     if (fp == NULL) {
 237         fatal_error("ERROR: %s: Unable to create output file\n", OUTPUT_FILE);
 238         return -1;
 239     }
 240 
 241     /* Get JVMTI environment */
 242     rc = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION);
 243     if (rc != JNI_OK) {
 244         fatal_error(
 245             "ERROR: Unable to create jvmtiEnv, GetEnv failed, error=%d\n", rc);
 246         return -1;
 247     }
 248 


 255     /* set JVMTI callbacks for events */
 256     memset(&callbacks, 0, sizeof(callbacks));
 257     callbacks.CompiledMethodLoad = &compiled_method_load;
 258     err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks));
 259     check_jvmti_error(jvmti, err, "set event callbacks");
 260 
 261     /* enable JVMTI events */
 262     err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
 263                         JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL);
 264     check_jvmti_error(jvmti, err, "set event notify");
 265 
 266     /* create coordination monitor */
 267     err = (*jvmti)->CreateRawMonitor(jvmti, "agent lock", &lock);
 268     check_jvmti_error(jvmti, err, "create raw monitor");
 269 
 270     return 0;
 271 }
 272 
 273 /* Agent_OnUnload() is called last */
 274 JNIEXPORT void JNICALL
 275 Agent_OnUnload(JavaVM *vm)
 276 {
 277 }
   1 /*
   2  * Copyright (c) 2010, 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


 208         err = (*jvmti)->Deallocate(jvmti, (unsigned char*)name);
 209         check_jvmti_error(jvmti, err, "deallocate name");
 210     }
 211     if (signature != NULL) {
 212         err = (*jvmti)->Deallocate(jvmti, (unsigned char*)signature);
 213         check_jvmti_error(jvmti, err, "deallocate signature");
 214     }
 215     if (generic_ptr != NULL) {
 216         err = (*jvmti)->Deallocate(jvmti, (unsigned char*)generic_ptr);
 217         check_jvmti_error(jvmti, err, "deallocate generic_ptr");
 218     }
 219 
 220     err = (*jvmti)->RawMonitorExit(jvmti, lock);
 221     check_jvmti_error(jvmti, err, "raw monitor exit");
 222 }
 223 
 224 /* Agent_OnLoad() is called first, we prepare for a COMPILED_METHOD_LOAD
 225  * event here.
 226  */
 227 JNIEXPORT jint JNICALL
 228 DEF_Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
 229 {
 230     jint                rc;
 231     jvmtiError          err;
 232     jvmtiCapabilities   capabilities;
 233     jvmtiEventCallbacks callbacks;
 234 
 235     fp = fopen(OUTPUT_FILE, "w");
 236     if (fp == NULL) {
 237         fatal_error("ERROR: %s: Unable to create output file\n", OUTPUT_FILE);
 238         return -1;
 239     }
 240 
 241     /* Get JVMTI environment */
 242     rc = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION);
 243     if (rc != JNI_OK) {
 244         fatal_error(
 245             "ERROR: Unable to create jvmtiEnv, GetEnv failed, error=%d\n", rc);
 246         return -1;
 247     }
 248 


 255     /* set JVMTI callbacks for events */
 256     memset(&callbacks, 0, sizeof(callbacks));
 257     callbacks.CompiledMethodLoad = &compiled_method_load;
 258     err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks));
 259     check_jvmti_error(jvmti, err, "set event callbacks");
 260 
 261     /* enable JVMTI events */
 262     err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
 263                         JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL);
 264     check_jvmti_error(jvmti, err, "set event notify");
 265 
 266     /* create coordination monitor */
 267     err = (*jvmti)->CreateRawMonitor(jvmti, "agent lock", &lock);
 268     check_jvmti_error(jvmti, err, "create raw monitor");
 269 
 270     return 0;
 271 }
 272 
 273 /* Agent_OnUnload() is called last */
 274 JNIEXPORT void JNICALL
 275 DEF_Agent_OnUnload(JavaVM *vm)
 276 {
 277 }
< prev index next >