annotate test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/refignore/refignore.c @ 51250:c9e7dc7976ae

8204961: JVMTI jtreg tests build warnings on 32-bit platforms Reviewed-by: sspitsyn, dholmes
author bulasevich
date Mon, 18 Jun 2018 20:50:23 -0400
parents 46c67f5e27c2
children
rev   line source
iignatyev@50844 1 /*
iignatyev@50844 2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
iignatyev@50844 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
iignatyev@50844 4 *
iignatyev@50844 5 * This code is free software; you can redistribute it and/or modify it
iignatyev@50844 6 * under the terms of the GNU General Public License version 2 only, as
iignatyev@50844 7 * published by the Free Software Foundation.
iignatyev@50844 8 *
iignatyev@50844 9 * This code is distributed in the hope that it will be useful, but WITHOUT
iignatyev@50844 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
iignatyev@50844 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
iignatyev@50844 12 * version 2 for more details (a copy is included in the LICENSE file that
iignatyev@50844 13 * accompanied this code).
iignatyev@50844 14 *
iignatyev@50844 15 * You should have received a copy of the GNU General Public License version
iignatyev@50844 16 * 2 along with this work; if not, write to the Free Software Foundation,
iignatyev@50844 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
iignatyev@50844 18 *
iignatyev@50844 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
iignatyev@50844 20 * or visit www.oracle.com if you need additional information or have any
iignatyev@50844 21 * questions.
iignatyev@50844 22 */
iignatyev@50844 23
iignatyev@50844 24 #include <stdio.h>
iignatyev@50844 25 #include <string.h>
iignatyev@50844 26 #include <stdlib.h>
iignatyev@50844 27 #include "jvmti.h"
iignatyev@50844 28 #include "jni_tools.h"
iignatyev@50844 29 #include "agent_common.h"
iignatyev@50844 30 #include "JVMTITools.h"
iignatyev@50844 31
iignatyev@50844 32 #ifdef __cplusplus
iignatyev@50844 33 extern "C" {
iignatyev@50844 34 #endif
iignatyev@50844 35
iignatyev@50844 36 #ifndef JNI_ENV_ARG
iignatyev@50844 37
iignatyev@50844 38 #ifdef __cplusplus
iignatyev@50844 39 #define JNI_ENV_ARG(x, y) y
iignatyev@50844 40 #define JNI_ENV_PTR(x) x
iignatyev@50844 41 #else
iignatyev@50844 42 #define JNI_ENV_ARG(x,y) x, y
iignatyev@50844 43 #define JNI_ENV_PTR(x) (*x)
iignatyev@50844 44 #endif
iignatyev@50844 45
iignatyev@50844 46 #endif
iignatyev@50844 47
iignatyev@50844 48 #define PASSED 0
iignatyev@50844 49 #define STATUS_FAILED 2
iignatyev@50844 50
iignatyev@50844 51 static jvmtiEnv *jvmti = NULL;
iignatyev@50844 52 static jint result = PASSED;
iignatyev@50844 53 static jboolean printdump = JNI_FALSE;
iignatyev@50844 54 static jvmtiCapabilities jvmti_caps;
iignatyev@50844 55 static jint dummy_user_data = 0;
iignatyev@50844 56 static jboolean user_data_error_flag = JNI_FALSE;
iignatyev@50844 57
iignatyev@50844 58 #define HEAP_ROOT_REF_KIND_BASE 100
iignatyev@50844 59 #define MISSED_REF_KIND_BASE 300
iignatyev@50844 60
iignatyev@50844 61 typedef enum {
iignatyev@50844 62 rthread,
iignatyev@50844 63 rclass,
iignatyev@50844 64 rother,
iignatyev@50844 65 rmark
iignatyev@50844 66 } refKind;
iignatyev@50844 67
iignatyev@50844 68 struct _refLink;
iignatyev@50844 69
iignatyev@50844 70 typedef struct _myTag {
iignatyev@50844 71 refKind kind;
iignatyev@50844 72 const struct _myTag* class_tag;
iignatyev@50844 73 jlong size;
iignatyev@50844 74 jlong sequence;
iignatyev@50844 75 jboolean visited;
iignatyev@50844 76 const char* name;
iignatyev@50844 77 struct _refLink *ref;
iignatyev@50844 78 } MyTag;
iignatyev@50844 79
iignatyev@50844 80 typedef struct _refLink {
iignatyev@50844 81 MyTag* tag;
iignatyev@50844 82 int reference_kind;
iignatyev@50844 83 struct _refLink *next;
iignatyev@50844 84 } refLink;
iignatyev@50844 85
iignatyev@50844 86 static MyTag *fakeRoot = NULL;
iignatyev@50844 87 static MyTag *missed = NULL;
iignatyev@50844 88
iignatyev@50844 89 static void breakpoint() {
iignatyev@50844 90 printf("Continuing from BREAKPOINT\n");
iignatyev@50844 91 }
iignatyev@50844 92
iignatyev@50844 93 static MyTag *newTag(refKind kind,
iignatyev@50844 94 const MyTag* class_tag,
iignatyev@50844 95 jlong size,
iignatyev@50844 96 const char* name) {
iignatyev@50844 97 static jlong seq_num = 0;
iignatyev@50844 98 MyTag* new_tag = NULL;
iignatyev@50844 99
iignatyev@50844 100 new_tag = malloc(sizeof(MyTag));
iignatyev@50844 101 if (NULL == new_tag) {
iignatyev@50844 102 printf("Error (newTag malloc): failed\n");
iignatyev@50844 103 result = STATUS_FAILED;
iignatyev@50844 104 }
iignatyev@50844 105 new_tag->kind = kind;
iignatyev@50844 106 new_tag->class_tag = class_tag;
iignatyev@50844 107 new_tag->size = size;
iignatyev@50844 108 new_tag->sequence = ++seq_num;
iignatyev@50844 109 new_tag->visited = JNI_FALSE;
iignatyev@50844 110 new_tag->name = name;
iignatyev@50844 111 new_tag->ref = NULL;
iignatyev@50844 112 return new_tag;
iignatyev@50844 113 }
iignatyev@50844 114
iignatyev@50844 115 static void setTag(JNIEnv *env,
iignatyev@50844 116 jobject obj,
iignatyev@50844 117 refKind kind,
iignatyev@50844 118 const char* name) {
iignatyev@50844 119 MyTag *new_tag = NULL;
iignatyev@50844 120 MyTag *class_tag = NULL;
iignatyev@50844 121 jvmtiError err;
iignatyev@50844 122 jlong size = 0;
iignatyev@50844 123 jclass obj_class = NULL;
iignatyev@50844 124 jlong haba = 0;
iignatyev@50844 125
iignatyev@50844 126 err = (*jvmti)->GetObjectSize(jvmti, obj, &size);
iignatyev@50844 127 if (err != JVMTI_ERROR_NONE) {
iignatyev@50844 128 printf("Error (ObjectSize): %s (%d)\n", TranslateError(err), err);
iignatyev@50844 129 result = STATUS_FAILED;
iignatyev@50844 130 }
iignatyev@50844 131
iignatyev@50844 132 obj_class = (*env)->GetObjectClass(env, obj);
iignatyev@50844 133
iignatyev@50844 134 err = (*jvmti)->GetTag(jvmti, obj_class, &haba);
bulasevich@51250 135 class_tag = (MyTag*)(intptr_t)haba;
iignatyev@50844 136 if (err != JVMTI_ERROR_NONE) {
iignatyev@50844 137 printf("Error (GetTag): %s (%d)\n", TranslateError(err), err);
iignatyev@50844 138 result = STATUS_FAILED;
iignatyev@50844 139 }
iignatyev@50844 140 if (class_tag != NULL && class_tag->kind != rclass) {
iignatyev@50844 141 printf("Error class tag which is not a class\n");
iignatyev@50844 142 result = STATUS_FAILED;
iignatyev@50844 143 }
iignatyev@50844 144
iignatyev@50844 145 new_tag = newTag(kind, class_tag, size, name);
iignatyev@50844 146
bulasevich@51250 147 err = (*jvmti)->SetTag(jvmti, obj, (intptr_t)new_tag);
iignatyev@50844 148 if (err != JVMTI_ERROR_NONE) {
iignatyev@50844 149 printf("Error (SetTag): %s (%d)\n", TranslateError(err), err);
iignatyev@50844 150 result = STATUS_FAILED;
iignatyev@50844 151 }
iignatyev@50844 152 }
iignatyev@50844 153
iignatyev@50844 154 static void addRef(MyTag *from, int reference_kind, MyTag *to) {
iignatyev@50844 155 refLink *new_ref;
iignatyev@50844 156
iignatyev@50844 157 new_ref = malloc(sizeof(refLink));
iignatyev@50844 158 if (NULL == new_ref) {
iignatyev@50844 159 printf("Error (addRef malloc): failed\n");
iignatyev@50844 160 result = STATUS_FAILED;
iignatyev@50844 161 }
iignatyev@50844 162 new_ref->tag = to;
iignatyev@50844 163 new_ref->reference_kind = reference_kind;
iignatyev@50844 164 new_ref->next = from->ref;
iignatyev@50844 165 from->ref = new_ref;
iignatyev@50844 166 }
iignatyev@50844 167
iignatyev@50844 168 static const char* reference_label(refLink *link) {
iignatyev@50844 169 int reference_kind = link->reference_kind;
iignatyev@50844 170 const char *name = "<font color=\"red\">**unknown**</font>";
iignatyev@50844 171 switch (reference_kind) {
iignatyev@50844 172 case JVMTI_REFERENCE_CLASS:
iignatyev@50844 173 name = "<font color=\"black\">class</font>";
iignatyev@50844 174 break;
iignatyev@50844 175 case JVMTI_REFERENCE_FIELD:
iignatyev@50844 176 name = "<font color=\"black\">field</font>";
iignatyev@50844 177 break;
iignatyev@50844 178 case JVMTI_REFERENCE_ARRAY_ELEMENT:
iignatyev@50844 179 name = "<font color=\"green\">array_element</font>";
iignatyev@50844 180 break;
iignatyev@50844 181 case JVMTI_REFERENCE_CLASS_LOADER:
iignatyev@50844 182 name = "<font color=\"purple\">class_loader</font>";
iignatyev@50844 183 break;
iignatyev@50844 184 case JVMTI_REFERENCE_SIGNERS:
iignatyev@50844 185 name = "<font color=\"purple\">signers</font>";
iignatyev@50844 186 break;
iignatyev@50844 187 case JVMTI_REFERENCE_PROTECTION_DOMAIN:
iignatyev@50844 188 name = "<font color=\"purple\">protection_domain</font>";
iignatyev@50844 189 break;
iignatyev@50844 190 case JVMTI_REFERENCE_INTERFACE:
iignatyev@50844 191 name = "<font color=\"purple\">interface</font>";
iignatyev@50844 192 break;
iignatyev@50844 193 case JVMTI_REFERENCE_STATIC_FIELD:
iignatyev@50844 194 name = "<font color=\"black\">static_field</font>";
iignatyev@50844 195 break;
iignatyev@50844 196 case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_JNI_GLOBAL:
iignatyev@50844 197 name = "<font color=\"orange\">root::jni_global</font>";
iignatyev@50844 198 break;
iignatyev@50844 199 case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_SYSTEM_CLASS:
iignatyev@50844 200 name = "<font color=\"orange\">root::system_class</font>";
iignatyev@50844 201 break;
iignatyev@50844 202 case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_MONITOR:
iignatyev@50844 203 name = "<font color=\"orange\">root::monitor</font>";
iignatyev@50844 204 break;
iignatyev@50844 205 case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_STACK_LOCAL:
iignatyev@50844 206 name = "<font color=\"orange\">root::local_var</font>";
iignatyev@50844 207 break;
iignatyev@50844 208 case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_JNI_LOCAL:
iignatyev@50844 209 name = "<font color=\"orange\">root::jni_local</font>";
iignatyev@50844 210 break;
iignatyev@50844 211 case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_THREAD:
iignatyev@50844 212 name = "<font color=\"orange\">root::thread</font>";
iignatyev@50844 213 break;
iignatyev@50844 214 case HEAP_ROOT_REF_KIND_BASE+JVMTI_HEAP_ROOT_OTHER:
iignatyev@50844 215 name = "<font color=\"orange\">root::other</font>";
iignatyev@50844 216 break;
iignatyev@50844 217 default:
iignatyev@50844 218 printf("Error: Unexpected reference kind %d\n", reference_kind);
iignatyev@50844 219 result = STATUS_FAILED;
iignatyev@50844 220 break;
iignatyev@50844 221 }
iignatyev@50844 222 return name;
iignatyev@50844 223 }
iignatyev@50844 224
iignatyev@50844 225 static void walk(MyTag* tag, jint depth, const char* ref_label) {
iignatyev@50844 226 static const char* const spaces = ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ";
iignatyev@50844 227 static const int len = 86;
iignatyev@50844 228 const char *indent = spaces + (len - 2 * depth);
iignatyev@50844 229
iignatyev@50844 230 const MyTag* const ctag = tag->class_tag;
iignatyev@50844 231 const char* const cname = ctag != NULL ? ctag->name : "";
iignatyev@50844 232
iignatyev@50844 233 printf("%s", indent);
iignatyev@50844 234
iignatyev@50844 235 if (tag->visited) {
iignatyev@50844 236 printf("<a href=\"#%"LL"d\">", tag->sequence);
iignatyev@50844 237 } else {
iignatyev@50844 238 printf("<a name=\"%"LL"d\">", tag->sequence);
iignatyev@50844 239 }
iignatyev@50844 240 if (tag->name) {
iignatyev@50844 241 printf("<b>%s(%s)</b>", cname, tag->name);
iignatyev@50844 242 } else {
iignatyev@50844 243 printf("%s(%"LL"d)", cname, tag->sequence);
iignatyev@50844 244 }
iignatyev@50844 245 printf("</a> -- ");
iignatyev@50844 246 printf("%s\n", ref_label);
iignatyev@50844 247 if (!tag->visited) {
iignatyev@50844 248 refLink *ref;
iignatyev@50844 249 tag->visited = JNI_TRUE;
iignatyev@50844 250 for (ref = tag->ref; ref; ref = ref->next) {
iignatyev@50844 251 walk(ref->tag, depth + 1, reference_label(ref));
iignatyev@50844 252 }
iignatyev@50844 253 }
iignatyev@50844 254 }
iignatyev@50844 255
iignatyev@50844 256 #ifdef STATIC_BUILD
iignatyev@50844 257 JNIEXPORT jint JNICALL Agent_OnLoad_refignore(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50844 258 return Agent_Initialize(jvm, options, reserved);
iignatyev@50844 259 }
iignatyev@50844 260 JNIEXPORT jint JNICALL Agent_OnAttach_refignore(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50844 261 return Agent_Initialize(jvm, options, reserved);
iignatyev@50844 262 }
iignatyev@50844 263 JNIEXPORT jint JNI_OnLoad_refignore(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50844 264 return JNI_VERSION_1_8;
iignatyev@50844 265 }
iignatyev@50844 266 #endif
iignatyev@50844 267
iignatyev@50844 268 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50844 269 jint res;
iignatyev@50844 270 jvmtiError err;
iignatyev@50844 271
iignatyev@50844 272 if (options != NULL && strcmp(options, "printdump") == 0) {
iignatyev@50844 273 printdump = JNI_TRUE;
iignatyev@50844 274 }
iignatyev@50844 275
iignatyev@50844 276 res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti),
iignatyev@50844 277 JVMTI_VERSION_1_1);
iignatyev@50844 278 if (res != JNI_OK || jvmti == NULL) {
iignatyev@50844 279 printf("Wrong result of a valid call to GetEnv!\n");
iignatyev@50844 280 return JNI_ERR;
iignatyev@50844 281 }
iignatyev@50844 282
iignatyev@50844 283 memset((void*)&jvmti_caps, 0, sizeof(jvmtiCapabilities));
iignatyev@50844 284 jvmti_caps.can_tag_objects = 1;
iignatyev@50844 285 err = (*jvmti)->AddCapabilities(jvmti, &jvmti_caps);
iignatyev@50844 286 if (err != JVMTI_ERROR_NONE) {
iignatyev@50844 287 printf("Error (AddCapabilities): %s (%d)\n", TranslateError(err), err);
iignatyev@50844 288 return JNI_ERR;
iignatyev@50844 289 }
iignatyev@50844 290
iignatyev@50844 291 return JNI_OK;
iignatyev@50844 292 }
iignatyev@50844 293
iignatyev@50844 294 jvmtiIterationControl JNICALL
iignatyev@50844 295 heapMarkCallback(jlong class_tag, jlong size, jlong* tag_ptr, void* user_data) {
bulasevich@51250 296 const MyTag* const tag = newTag(rmark, (const MyTag*)(intptr_t)class_tag, size, NULL);
bulasevich@51250 297 *tag_ptr = (intptr_t)tag;
iignatyev@50844 298
iignatyev@50844 299 if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) {
iignatyev@50844 300 user_data_error_flag = JNI_TRUE;
iignatyev@50844 301 printf("Error (heapMarkCallback): unexpected value of user_data\n");
iignatyev@50844 302 result = STATUS_FAILED;
iignatyev@50844 303 }
iignatyev@50844 304 return JVMTI_ITERATION_CONTINUE;
iignatyev@50844 305 }
iignatyev@50844 306
iignatyev@50844 307 jvmtiIterationControl JNICALL
iignatyev@50844 308 heapRootCallback(jvmtiHeapRootKind root_kind,
iignatyev@50844 309 jlong class_tag, jlong size,
iignatyev@50844 310 jlong* tag_ptr, void* user_data) {
iignatyev@50844 311 refKind kind = rother;
iignatyev@50844 312
iignatyev@50844 313 if (0 == *tag_ptr) {
iignatyev@50844 314 /* new tag */
bulasevich@51250 315 MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL);
iignatyev@50844 316 addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, tag);
bulasevich@51250 317 *tag_ptr = (intptr_t)tag;
iignatyev@50844 318 } else {
iignatyev@50844 319 /* existing tag */
bulasevich@51250 320 addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, (MyTag*)(intptr_t)*tag_ptr);
iignatyev@50844 321 }
iignatyev@50844 322
iignatyev@50844 323 if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) {
iignatyev@50844 324 user_data_error_flag = JNI_TRUE;
iignatyev@50844 325 printf("Error (heapRootCallback): unexpected value of user_data\n");
iignatyev@50844 326 result = STATUS_FAILED;
iignatyev@50844 327 }
iignatyev@50844 328 return JVMTI_ITERATION_CONTINUE;
iignatyev@50844 329 }
iignatyev@50844 330
iignatyev@50844 331 jvmtiIterationControl JNICALL
iignatyev@50844 332 stackReferenceCallback(jvmtiHeapRootKind root_kind,
iignatyev@50844 333 jlong class_tag, jlong size,
iignatyev@50844 334 jlong* tag_ptr, jlong thread_tag,
iignatyev@50844 335 jint depth, jmethodID method,
iignatyev@50844 336 jint slot, void* user_data) {
iignatyev@50844 337 refKind kind = rother;
iignatyev@50844 338
iignatyev@50844 339 if (0 == *tag_ptr) {
iignatyev@50844 340 /* new tag */
bulasevich@51250 341 MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL);
iignatyev@50844 342 addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, tag);
bulasevich@51250 343 *tag_ptr = (intptr_t)tag;
iignatyev@50844 344 } else {
iignatyev@50844 345 /* existing tag */
bulasevich@51250 346 addRef(fakeRoot, HEAP_ROOT_REF_KIND_BASE+root_kind, (MyTag*)(intptr_t)*tag_ptr);
iignatyev@50844 347 }
iignatyev@50844 348 if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) {
iignatyev@50844 349 user_data_error_flag = JNI_TRUE;
iignatyev@50844 350 printf("Error (stackReferenceCallback): unexpected value of user_data\n");
iignatyev@50844 351 result = STATUS_FAILED;
iignatyev@50844 352 }
iignatyev@50844 353 return JVMTI_ITERATION_CONTINUE;
iignatyev@50844 354 }
iignatyev@50844 355
iignatyev@50844 356 jvmtiIterationControl JNICALL
iignatyev@50844 357 objectReferenceCallback(jvmtiObjectReferenceKind reference_kind,
iignatyev@50844 358 jlong class_tag, jlong size,
iignatyev@50844 359 jlong* tag_ptr, jlong referrer_tag,
iignatyev@50844 360 jint referrer_index, void* user_data) {
iignatyev@50844 361 refKind kind = rother;
iignatyev@50844 362 MyTag* referrer = NULL;
iignatyev@50844 363
iignatyev@50844 364 if (0 == referrer_tag) {
iignatyev@50844 365 referrer = missed;
iignatyev@50844 366 } else {
bulasevich@51250 367 referrer = (MyTag *)(intptr_t)referrer_tag;
iignatyev@50844 368 }
iignatyev@50844 369
iignatyev@50844 370 if (0 == *tag_ptr) {
iignatyev@50844 371 /* new tag */
bulasevich@51250 372 MyTag* tag = newTag(kind, (MyTag*)(intptr_t)class_tag, size, NULL);
iignatyev@50844 373 addRef(referrer, reference_kind, tag);
bulasevich@51250 374 *tag_ptr = (intptr_t) tag;
iignatyev@50844 375 } else {
iignatyev@50844 376 /* existing tag */
bulasevich@51250 377 MyTag* tag = (MyTag*)(intptr_t)*tag_ptr;
iignatyev@50844 378 addRef(referrer, reference_kind, tag);
iignatyev@50844 379 }
iignatyev@50844 380 if (user_data != &dummy_user_data && user_data_error_flag == JNI_FALSE) {
iignatyev@50844 381 user_data_error_flag = JNI_TRUE;
iignatyev@50844 382 printf("Error (objectReferenceCallback): unexpected value of user_data\n");
iignatyev@50844 383 result = STATUS_FAILED;
iignatyev@50844 384 }
iignatyev@50844 385 return JVMTI_ITERATION_IGNORE;
iignatyev@50844 386 }
iignatyev@50844 387
iignatyev@50844 388 JNIEXPORT jint JNICALL
iignatyev@50844 389 Java_nsk_jvmti_unit_refignore_check(JNIEnv *env, jclass cls) {
iignatyev@50844 390 jvmtiError err;
iignatyev@50844 391 jclass *classes;
iignatyev@50844 392 jint classCount = 0;
iignatyev@50844 393 jthread *threads;
iignatyev@50844 394 jint threadCount = 0;
iignatyev@50844 395 jint i;
iignatyev@50844 396
iignatyev@50844 397 if (jvmti == NULL) {
iignatyev@50844 398 printf("JVMTI client was not properly loaded!\n");
iignatyev@50844 399 return STATUS_FAILED;
iignatyev@50844 400 }
iignatyev@50844 401
iignatyev@50844 402 fakeRoot = newTag(rother, (const MyTag *)NULL, 0, "FAKE_ROOT");
iignatyev@50844 403 missed = newTag(rother, (const MyTag *)NULL, 0, "MISSED");
iignatyev@50844 404
iignatyev@50844 405 if ((*env)->PushLocalFrame(env, 500) != 0) {
iignatyev@50844 406 printf("Error (PushLocalFrame): failed\n");
iignatyev@50844 407 result = STATUS_FAILED;
iignatyev@50844 408 }
iignatyev@50844 409
iignatyev@50844 410 err = (*jvmti)->GetLoadedClasses(jvmti, &classCount, &classes);
iignatyev@50844 411 if (err != JVMTI_ERROR_NONE) {
iignatyev@50844 412 printf("Error (GetLoadedClasses): %s (%d)\n", TranslateError(err), err);
iignatyev@50844 413 result = STATUS_FAILED;
iignatyev@50844 414 }
iignatyev@50844 415
iignatyev@50844 416 for (i = 0; i < classCount; ++i) {
iignatyev@50844 417 char *classSig;
iignatyev@50844 418 jclass k = classes[i];
iignatyev@50844 419 err = (*jvmti)->GetClassSignature(jvmti, k, &classSig, NULL);
iignatyev@50844 420 if (err != JVMTI_ERROR_NONE) {
iignatyev@50844 421 printf("Error (getClassSignature): %s (%d)\n", TranslateError(err), err);
iignatyev@50844 422 result = STATUS_FAILED;
iignatyev@50844 423 } else {
iignatyev@50844 424 char* slash = strrchr(classSig, '/');
iignatyev@50844 425 const size_t len = strlen(classSig);
iignatyev@50844 426 if (classSig[len-1] == ';') {
iignatyev@50844 427 classSig[len-1] = 0;
iignatyev@50844 428 }
iignatyev@50844 429 if (*classSig == 'L' && slash != NULL) {
iignatyev@50844 430 classSig = slash + 1;
iignatyev@50844 431 }
iignatyev@50844 432 setTag(env, k, rclass, (const char*)classSig);
iignatyev@50844 433 }
iignatyev@50844 434 }
iignatyev@50844 435
iignatyev@50844 436 err = (*jvmti)->GetAllThreads(jvmti, &threadCount, &threads);
iignatyev@50844 437 if (err != JVMTI_ERROR_NONE) {
iignatyev@50844 438 printf("Error (GetAllThreads): %s (%d)\n", TranslateError(err), err);
iignatyev@50844 439 result = STATUS_FAILED;
iignatyev@50844 440 }
iignatyev@50844 441
iignatyev@50844 442 for (i = 0; i < threadCount; ++i) {
iignatyev@50844 443 jvmtiThreadInfo info;
iignatyev@50844 444 jthread t = threads[i];
iignatyev@50844 445 err = (*jvmti)->GetThreadInfo(jvmti, t, &info);
iignatyev@50844 446 if (err != JVMTI_ERROR_NONE) {
iignatyev@50844 447 printf("Error (GetThreadInfo): %s (%d)\n", TranslateError(err), err);
iignatyev@50844 448 result = STATUS_FAILED;
iignatyev@50844 449 } else {
iignatyev@50844 450 setTag(env, t, rthread, (const char*)info.name);
iignatyev@50844 451 }
iignatyev@50844 452 }
iignatyev@50844 453
iignatyev@50844 454 (*env)->PopLocalFrame(env, NULL);
iignatyev@50844 455
iignatyev@50844 456 user_data_error_flag = JNI_FALSE;
iignatyev@50844 457 err = (*jvmti)->IterateOverHeap(jvmti,
iignatyev@50844 458 JVMTI_HEAP_OBJECT_UNTAGGED,
iignatyev@50844 459 heapMarkCallback,
iignatyev@50844 460 &dummy_user_data);
iignatyev@50844 461 if (err != JVMTI_ERROR_NONE) {
iignatyev@50844 462 printf("Error (IterateOverHeap): %s (%d)\n", TranslateError(err), err);
iignatyev@50844 463 result = STATUS_FAILED;
iignatyev@50844 464 }
iignatyev@50844 465
iignatyev@50844 466 user_data_error_flag = JNI_FALSE;
iignatyev@50844 467 err = (*jvmti)->IterateOverReachableObjects(jvmti,
iignatyev@50844 468 heapRootCallback,
iignatyev@50844 469 stackReferenceCallback,
iignatyev@50844 470 objectReferenceCallback,
iignatyev@50844 471 &dummy_user_data);
iignatyev@50844 472 if (err != JVMTI_ERROR_NONE) {
iignatyev@50844 473 printf("Error (IterateOverReachableObjects): %s (%d)\n", TranslateError(err), err);
iignatyev@50844 474 result = STATUS_FAILED;
iignatyev@50844 475 }
iignatyev@50844 476
iignatyev@50844 477 if (printdump == JNI_TRUE) {
iignatyev@50844 478 printf("<html><head><title>Heap Dump</title></head><body><pre>\n");
iignatyev@50844 479 walk(fakeRoot, 0, "roots");
iignatyev@50844 480 printf("\n------------------- MISSED ------------------\n\n");
iignatyev@50844 481 walk(missed, 0, "missed");
iignatyev@50844 482 printf("</pre></body></html>\n");
iignatyev@50844 483 }
iignatyev@50844 484
iignatyev@50844 485 return result;
iignatyev@50844 486 }
iignatyev@50844 487
iignatyev@50844 488 #ifdef __cplusplus
iignatyev@50844 489 }
iignatyev@50844 490 #endif