< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/functions/environment/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 
  59 
  60 jvmtiEnv *jvmti;
  61 jint iGlobalStatus = 0;
  62 static jvmtiCapabilities jvmti_caps;
  63 
  64 
  65 
  66 int printdump = 0;
  67 
  68 
  69 void debug_printf(const char *fmt, ...) {


  82 }
  83 JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) {
  84     return Agent_Initialize(jvm, options, reserved);
  85 }
  86 JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) {
  87     return JNI_VERSION_1_8;
  88 }
  89 #endif
  90 jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) {
  91     jint res;
  92     jint count;
  93     char **properties;
  94     int i;
  95 
  96     if (options && strlen(options) > 0) {
  97         if (strstr(options, "printdump")) {
  98             printdump = 1;
  99         }
 100     }
 101 
 102     res = JNI_ENV_PTR(jvm)->
 103         GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti), JVMTI_VERSION_1_1);
 104     if (res < 0) {
 105         debug_printf("Wrong result of a valid call to GetEnv!\n");
 106         return JNI_ERR;
 107     }
 108 
 109 
 110     /* Add capabilities */
 111     res = JVMTI_ENV_PTR(jvmti)->GetPotentialCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps));
 112     JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res);
 113 
 114     res = JVMTI_ENV_PTR(jvmti)->AddCapabilities(JVMTI_ENV_ARG(jvmti, &jvmti_caps));
 115     JVMTI_ERROR_CHECK("GetAddCapabilities returned error", res);
 116 
 117 
 118     res = JVMTI_ENV_PTR(jvmti)->GetSystemProperties(JVMTI_ENV_ARG(jvmti, &count), &properties);
 119 
 120     JVMTI_ERROR_CHECK("GetSystemProperties returned error", res);
 121 
 122     for (i=0; i< count; i++) {
 123         char *value;
 124 
 125         res = JVMTI_ENV_PTR(jvmti)->GetSystemProperty(JVMTI_ENV_ARG(jvmti, (const char *)properties[i]), &value);
 126         JVMTI_ERROR_CHECK("GetSystemProperty returned error", res);
 127         debug_printf(" %s    %s \n", properties[i], value);
 128 
 129         /* Only writeable properties returns JVMTI_ERROR_NONE. */
 130         res = JVMTI_ENV_PTR(jvmti)->SetSystemProperty(JVMTI_ENV_ARG(jvmti, (const char *)properties[i]), value);
 131         debug_printf("SetSystemProperty returned error %d\n", res);
 132 
 133      }
 134 
 135     return JNI_OK;
 136 }
 137 
 138 
 139 JNIEXPORT jint JNICALL
 140 Java_nsk_jvmti_unit_functions_environment_JvmtiTest_GetResult(JNIEnv * env, jclass cls) {
 141     return iGlobalStatus;
 142 }
 143 
 144 
 145 #ifdef __cplusplus
 146 }
 147 #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 
  40 
  41 jvmtiEnv *jvmti;
  42 jint iGlobalStatus = 0;
  43 static jvmtiCapabilities jvmti_caps;
  44 
  45 
  46 
  47 int printdump = 0;
  48 
  49 
  50 void debug_printf(const char *fmt, ...) {


  63 }
  64 JNIEXPORT jint JNICALL Agent_OnAttach_JvmtiTest(JavaVM *jvm, char *options, void *reserved) {
  65     return Agent_Initialize(jvm, options, reserved);
  66 }
  67 JNIEXPORT jint JNI_OnLoad_JvmtiTest(JavaVM *jvm, char *options, void *reserved) {
  68     return JNI_VERSION_1_8;
  69 }
  70 #endif
  71 jint Agent_Initialize(JavaVM * jvm, char *options, void *reserved) {
  72     jint res;
  73     jint count;
  74     char **properties;
  75     int i;
  76 
  77     if (options && strlen(options) > 0) {
  78         if (strstr(options, "printdump")) {
  79             printdump = 1;
  80         }
  81     }
  82 
  83     res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);

  84     if (res < 0) {
  85         debug_printf("Wrong result of a valid call to GetEnv!\n");
  86         return JNI_ERR;
  87     }
  88 
  89 
  90     /* Add capabilities */
  91     res = jvmti->GetPotentialCapabilities(&jvmti_caps);
  92     JVMTI_ERROR_CHECK("GetPotentialCapabilities returned error", res);
  93 
  94     res = jvmti->AddCapabilities(&jvmti_caps);
  95     JVMTI_ERROR_CHECK("GetAddCapabilities returned error", res);
  96 
  97 
  98     res = jvmti->GetSystemProperties(&count, &properties);
  99 
 100     JVMTI_ERROR_CHECK("GetSystemProperties returned error", res);
 101 
 102     for (i=0; i< count; i++) {
 103         char *value;
 104 
 105         res = jvmti->GetSystemProperty((const char *) properties[i], &value);
 106         JVMTI_ERROR_CHECK("GetSystemProperty returned error", res);
 107         debug_printf(" %s    %s \n", properties[i], value);
 108 
 109         /* Only writeable properties returns JVMTI_ERROR_NONE. */
 110         res = jvmti->SetSystemProperty((const char *) properties[i], value);
 111         debug_printf("SetSystemProperty returned error %d\n", res);
 112 
 113      }
 114 
 115     return JNI_OK;
 116 }
 117 
 118 
 119 JNIEXPORT jint JNICALL
 120 Java_nsk_jvmti_unit_functions_environment_JvmtiTest_GetResult(JNIEnv * env, jclass cls) {
 121     return iGlobalStatus;
 122 }
 123 
 124 

 125 }

< prev index next >