< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/nosuspendMonitorInfo/JvmtiTest/JvmtiTest.cpp

Print this page
rev 51722 : 8210700: Clean up JNI_ENV_ARG and factorize the macros for vmTestbase/jvmti/unit tests
Summary:
Reviewed-by:


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 #include <stdio.h>
  25 #include <string.h>
  26 #include "jvmti.h"
  27 #include "agent_common.h"
  28 
  29 #ifdef __cplusplus
  30 extern "C" {
  31 #endif
  32 
  33 #ifndef JNI_ENV_ARG
  34 
  35 #ifdef __cplusplus
  36 #define JNI_ENV_ARG(x, y) y
  37 #define JNI_ENV_ARG1(x)
  38 #define JNI_ENV_PTR(x) x
  39 #else
  40 #define JNI_ENV_ARG(x,y) x, y
  41 #define JNI_ENV_ARG1(x) x
  42 #define JNI_ENV_PTR(x) (*x)
  43 #endif
  44 
  45 #endif
  46 
  47 #define JVMTI_ENV_ARG JNI_ENV_ARG
  48 #define JVMTI_ENV_ARG1 JNI_ENV_ARG1
  49 #define JVMTI_ENV_PTR JNI_ENV_PTR
  50 
  51 #define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;}
  52 #define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;}
  53 
  54 #define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; }
  55 
  56 #define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; }
  57 
  58 #define THREADS_LIMIT 2000
  59 
  60 
  61 jvmtiEnv *jvmti;
  62 jint iGlobalStatus = 0;
  63 jthread susp_thrd[THREADS_LIMIT];
  64 static jvmtiEventCallbacks callbacks;
  65 static jvmtiCapabilities jvmti_caps;
  66 jrawMonitorID jraw_monitor[20];
  67 
  68 int process_once = 0;
  69 


 117 #ifdef STATIC_BUILD
 118 JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) {
 119     return Agent_Initialize(jvm, options, reserved);
 120 }
 121 JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) {
 122     return Agent_Initialize(jvm, options, reserved);
 123 }
 124 JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) {
 125     return JNI_VERSION_1_8;
 126 }
 127 #endif
 128 jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) {
 129     jint res;
 130 
 131     if (options && strlen(options) > 0) {
 132         if (strstr(options, "printdump")) {
 133             printdump = 1;
 134         }
 135     }
 136 
 137     res = JNI_ENV_PTR(jvm)->
 138         GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1);
 139     if (res < 0) {
 140         debug_printf("Wrong result of a valid call to GetEnv!\n");
 141         return JNI_ERR;
 142     }
 143 
 144 
 145     /* Add capabilities */
 146     res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps));
 147     JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res);
 148 
 149     res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps));
 150     JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res);
 151 
 152     /* Enable events */
 153     init_callbacks();
 154     res = JVMTI_ENV_PTR(jvmti)->SetEventCallbacks(JVMTI_ENV_ARG(jvmti, &callbacks), sizeof(callbacks));
 155     JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res);
 156 
 157     res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_INIT,NULL);
 158     JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res);
 159 
 160     res = JVMTI_ENV_PTR(jvmti)->SetEventNotificationMode(JVMTI_ENV_ARG(jvmti,JVMTI_ENABLE),JVMTI_EVENT_VM_DEATH,NULL);
 161     JVMTI_ERROR_CHECK("SetEventNotificationMode for vm death event returned error", res);
 162 
 163     return JNI_OK;
 164 }
 165 
 166 
 167 JNIEXPORT jint JNICALL
 168 Java_nsk_jvmti_unit_functions_nosuspendMonitorInfo_JvmtiTest_GetResult(JNIEnv * env, jclass cls) {
 169     return iGlobalStatus;
 170 }
 171 
 172 JNIEXPORT void JNICALL
 173 Java_nsk_jvmti_unit_functions_nosuspendMonitorInfo_JvmtiTest_CheckMonitorInfo(JNIEnv * env, jclass cls, jthread thr, jobject oobj, jint expected_count) {
 174 
 175   jvmtiError ret;
 176   jint count;
 177   jobject *owned_monitor;
 178 
 179   debug_printf(" jvmti GetMonitorInfo \n");
 180 
 181 
 182     ret = JVMTI_ENV_PTR(jvmti)->GetOwnedMonitorInfo(JVMTI_ENV_ARG(jvmti, thr), &count , &owned_monitor);
 183     if (ret != JVMTI_ERROR_NONE) {
 184         printf("Error: GetMonitorInfo %d \n", ret);
 185         iGlobalStatus = 2;
 186     }
 187 
 188     if (expected_count != 0 && expected_count != count) {
 189         printf("Error: GetMonitorInfo expected count %d but got %d \n", expected_count, count);
 190         iGlobalStatus = 2;
 191     }
 192 
 193     if (expected_count !=0 ) {
 194 
 195         ret = JVMTI_ENV_PTR(jvmti)->GetCurrentContendedMonitor(JVMTI_ENV_ARG(jvmti, thr), owned_monitor);
 196         if (ret != JVMTI_ERROR_NONE) {
 197             printf("Error: GetContendedMonitorInfo %d \n", ret);
 198             iGlobalStatus = 2;
 199         }
 200     }
 201 
 202 }
 203 
 204 #ifdef __cplusplus
 205 }
 206 #endif


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 #include <stdio.h>
  25 #include <string.h>
  26 #include "jvmti.h"
  27 #include "agent_common.h"
  28 

  29 extern "C" {



  30 















  31 
  32 #define JVMTI_ERROR_CHECK(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); return res;}
  33 #define JVMTI_ERROR_CHECK_EXPECTED_ERROR(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); return res;}
  34 
  35 #define JVMTI_ERROR_CHECK_VOID(str,res) if ( res != JVMTI_ERROR_NONE) { printf(str); printf("%d\n",res); iGlobalStatus = 2; }
  36 
  37 #define JVMTI_ERROR_CHECK_EXPECTED_ERROR_VOID(str,res,err) if ( res != err) { printf(str); printf("unexpected error %d\n",res); iGlobalStatus = 2; }
  38 
  39 #define THREADS_LIMIT 2000
  40 
  41 
  42 jvmtiEnv *jvmti;
  43 jint iGlobalStatus = 0;
  44 jthread susp_thrd[THREADS_LIMIT];
  45 static jvmtiEventCallbacks callbacks;
  46 static jvmtiCapabilities jvmti_caps;
  47 jrawMonitorID jraw_monitor[20];
  48 
  49 int process_once = 0;
  50 


  98 #ifdef STATIC_BUILD
  99 JNIEXPORT jint JNICALL Agent_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) {
 100     return Agent_Initialize(jvm, options, reserved);
 101 }
 102 JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) {
 103     return Agent_Initialize(jvm, options, reserved);
 104 }
 105 JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) {
 106     return JNI_VERSION_1_8;
 107 }
 108 #endif
 109 jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) {
 110     jint res;
 111 
 112     if (options && strlen(options) > 0) {
 113         if (strstr(options, "printdump")) {
 114             printdump = 1;
 115         }
 116     }
 117 
 118     res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);

 119     if (res < 0) {
 120         debug_printf("Wrong result of a valid call to GetEnv!\n");
 121         return JNI_ERR;
 122     }
 123 
 124 
 125     /* Add capabilities */
 126     res = jvmti->GetPotentialCapabilities(&jvmti_caps);
 127     JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res);
 128 
 129     res = jvmti->AddCapabilities(&jvmti_caps);
 130     JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res);
 131 
 132     /* Enable events */
 133     init_callbacks();
 134     res = jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks));
 135     JVMTI_ERROR_CHECK("SetEventCallbacks returned error", res);
 136 
 137     res = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, NULL);
 138     JVMTI_ERROR_CHECK("SetEventNotificationMode for VM_INIT returned error", res);
 139 
 140     res = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL);
 141     JVMTI_ERROR_CHECK("SetEventNotificationMode for vm death event returned error", res);
 142 
 143     return JNI_OK;
 144 }
 145 
 146 
 147 JNIEXPORT jint JNICALL
 148 Java_nsk_jvmti_unit_functions_nosuspendMonitorInfo_JvmtiTest_GetResult(JNIEnv * env, jclass cls) {
 149     return iGlobalStatus;
 150 }
 151 
 152 JNIEXPORT void JNICALL
 153 Java_nsk_jvmti_unit_functions_nosuspendMonitorInfo_JvmtiTest_CheckMonitorInfo(JNIEnv * env, jclass cls, jthread thr, jobject oobj, jint expected_count) {
 154 
 155   jvmtiError ret;
 156   jint count;
 157   jobject *owned_monitor;
 158 
 159   debug_printf(" jvmti GetMonitorInfo \n");
 160 
 161 
 162     ret = jvmti->GetOwnedMonitorInfo(thr, &count, &owned_monitor);
 163     if (ret != JVMTI_ERROR_NONE) {
 164         printf("Error: GetMonitorInfo %d \n", ret);
 165         iGlobalStatus = 2;
 166     }
 167 
 168     if (expected_count != 0 && expected_count != count) {
 169         printf("Error: GetMonitorInfo expected count %d but got %d \n", expected_count, count);
 170         iGlobalStatus = 2;
 171     }
 172 
 173     if (expected_count !=0) {
 174 
 175         ret = jvmti->GetCurrentContendedMonitor(thr, owned_monitor);
 176         if (ret != JVMTI_ERROR_NONE) {
 177             printf("Error: GetContendedMonitorInfo %d \n", ret);
 178             iGlobalStatus = 2;
 179         }
 180     }
 181 
 182 }
 183 

 184 }

< prev index next >