1 /*
   2  * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   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 #ifndef __FollowRefObject_h
  24 #define __FollowRefObject_h
  25 
  26 #include <jvmti.h>
  27 
  28 #ifdef __cplusplus
  29 extern "C" {
  30 #endif
  31 
  32 /* ============================================================================= */
  33 
  34 void jvmti_FollowRefObject_init();
  35 
  36 /* ============================================================================= */
  37 
  38 #define DBG(x) x
  39 #define DEREF(ptr) (((ptr) == NULL ? 0 : *(ptr)))
  40 
  41 extern jvmtiHeapCallbacks g_wrongHeapCallbacks; /* Callbacks that blame */
  42 
  43 extern const char * const g_refKindStr[28]; /* JVMTI_HEAP_REFERENCE_xxx */
  44 
  45 /* ============================================================================= */
  46 
  47 #define MAX_TAG 1000
  48 #define MAX_REFS (MAX_TAG * 3)
  49 
  50 #define FLAG_TAG_SET      0x01
  51 
  52 extern char * g_szTagInfo[MAX_TAG];
  53 extern char g_tagFlags[MAX_TAG];
  54 extern int g_tagVisitCount[MAX_TAG];
  55 
  56 void markTagSet(jlong tag_val);
  57 void markTagVisited(jlong tag_val);
  58 
  59 jboolean checkThatAllTagsVisited();
  60 
  61 /* ============================================================================= */
  62 
  63 typedef struct {
  64 
  65     jlong _tagFrom,
  66           _tagTo;
  67 
  68     jint  _refKind;
  69 
  70     int   _expectedCount,
  71           _actualCount;
  72 
  73 } RefToVerify;
  74 
  75 extern int g_refsToVerifyCnt;
  76 
  77 extern RefToVerify g_refsToVerify[MAX_REFS];
  78 
  79 jboolean markRefToVerify(jlong tagFrom, jlong tagTo, int refKind);
  80 
  81 /* ============================================================================= */
  82 
  83 extern int g_fakeUserData;
  84 extern int g_userDataError;
  85 
  86 #define CHECK_USER_DATA(p) checkUserData(__FILE__, __LINE__, (p))
  87 
  88 void checkUserData(const char * szFile, const int line, void * user_data);
  89 
  90 /* ============================================================================= */
  91 
  92 void printHeapRefCallbackInfo(
  93      jvmtiHeapReferenceKind        reference_kind,
  94      const jvmtiHeapReferenceInfo* reference_info,
  95      jlong                         class_tag,
  96      jlong                         referrer_class_tag,
  97      jlong                         size,
  98      jlong*                        tag_ptr,
  99      jlong*                        referrer_tag_ptr,
 100      jint                          length);
 101 
 102 /* ============================================================================= */
 103 
 104 #ifdef __cplusplus
 105 }
 106 #endif
 107 
 108 #endif