< prev index next >

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


  72 
  73 /* Callback for JVMTI_EVENT_VM_INIT */
  74 static void JNICALL
  75 vm_init(jvmtiEnv *jvmti, JNIEnv *env, jthread thread)
  76 {
  77     jvmtiError err;
  78     jint       runtime_version;
  79 
  80     /* The exact JVMTI version doesn't have to match, however this
  81      *  code demonstrates how you can check that the JVMTI version seen
  82      *  in the jvmti.h include file matches that being supplied at runtime
  83      *  by the VM.
  84      */
  85     err = (*jvmti)->GetVersionNumber(jvmti, &runtime_version);
  86     check_jvmti_error(jvmti, err, "get version number");
  87     version_check(JVMTI_VERSION, runtime_version);
  88 }
  89 
  90 /* Agent_OnLoad() is called first, we prepare for a VM_INIT event here. */
  91 JNIEXPORT jint JNICALL
  92 Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
  93 {
  94     jint                rc;
  95     jvmtiError          err;
  96     jvmtiEventCallbacks callbacks;
  97     jvmtiEnv           *jvmti;
  98 
  99     /* Get JVMTI environment */
 100     rc = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION);
 101     if (rc != JNI_OK) {
 102         fatal_error("ERROR: Unable to create jvmtiEnv, GetEnv failed, error=%d\n", rc);
 103         return -1;
 104     }
 105 
 106     /* Set callbacks and enable event notifications */
 107     memset(&callbacks, 0, sizeof(callbacks));
 108     callbacks.VMInit                  = &vm_init;
 109     err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks));
 110     check_jvmti_error(jvmti, err, "set event callbacks");
 111     err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
 112                         JVMTI_EVENT_VM_INIT, NULL);
 113     check_jvmti_error(jvmti, err, "set event notify");
 114     return 0;
 115 }
 116 
 117 /* Agent_OnUnload() is called last */
 118 JNIEXPORT void JNICALL
 119 Agent_OnUnload(JavaVM *vm)
 120 {
 121 }
   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


  72 
  73 /* Callback for JVMTI_EVENT_VM_INIT */
  74 static void JNICALL
  75 vm_init(jvmtiEnv *jvmti, JNIEnv *env, jthread thread)
  76 {
  77     jvmtiError err;
  78     jint       runtime_version;
  79 
  80     /* The exact JVMTI version doesn't have to match, however this
  81      *  code demonstrates how you can check that the JVMTI version seen
  82      *  in the jvmti.h include file matches that being supplied at runtime
  83      *  by the VM.
  84      */
  85     err = (*jvmti)->GetVersionNumber(jvmti, &runtime_version);
  86     check_jvmti_error(jvmti, err, "get version number");
  87     version_check(JVMTI_VERSION, runtime_version);
  88 }
  89 
  90 /* Agent_OnLoad() is called first, we prepare for a VM_INIT event here. */
  91 JNIEXPORT jint JNICALL
  92 DEF_Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
  93 {
  94     jint                rc;
  95     jvmtiError          err;
  96     jvmtiEventCallbacks callbacks;
  97     jvmtiEnv           *jvmti;
  98 
  99     /* Get JVMTI environment */
 100     rc = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION);
 101     if (rc != JNI_OK) {
 102         fatal_error("ERROR: Unable to create jvmtiEnv, GetEnv failed, error=%d\n", rc);
 103         return -1;
 104     }
 105 
 106     /* Set callbacks and enable event notifications */
 107     memset(&callbacks, 0, sizeof(callbacks));
 108     callbacks.VMInit                  = &vm_init;
 109     err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks));
 110     check_jvmti_error(jvmti, err, "set event callbacks");
 111     err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
 112                         JVMTI_EVENT_VM_INIT, NULL);
 113     check_jvmti_error(jvmti, err, "set event notify");
 114     return 0;
 115 }
 116 
 117 /* Agent_OnUnload() is called last */
 118 JNIEXPORT void JNICALL
 119 DEF_Agent_OnUnload(JavaVM *vm)
 120 {
 121 }
< prev index next >