generateJvmOffsets.cpp 9.2 KB
Newer Older
D
dcubed 已提交
1
/*
D
drchase 已提交
2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
D
dcubed 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

/*
 * This is to provide sanity check in jhelper.d which compares SCCS
 * versions of generateJvmOffsets.cpp used to create and extract
 * contents of __JvmOffsets[] table.
 * The __JvmOffsets[] table is located in generated JvmOffsets.cpp.
 *
 * GENOFFS_SCCS_VER 34
 */

#include "generateJvmOffsets.h"

/* A workaround for private and protected fields */
#define private   public
#define protected public

// not on macosx #include <proc_service.h>
#include "code/codeBlob.hpp"
#include "code/nmethod.hpp"
#include "code/pcDesc.hpp"
#include "gc_interface/collectedHeap.hpp"
#include "memory/heap.hpp"
#include "memory/memRegion.hpp"
#include "memory/universe.hpp"
48
#include "oops/constMethod.hpp"
D
dcubed 已提交
49
#include "oops/klass.hpp"
50
#include "oops/method.hpp"
D
dcubed 已提交
51 52 53 54 55 56 57 58 59 60 61 62
#include "oops/oop.hpp"
#include "oops/symbol.hpp"
#include "runtime/virtualspace.hpp"
#include "runtime/vmStructs.hpp"
#include "utilities/accessFlags.hpp"
#include "utilities/globalDefinitions.hpp"

// These are defined somewhere for Solaris
#define PR_MODEL_ILP32 1
#define PR_MODEL_LP64  2

#ifdef COMPILER1
D
drchase 已提交
63
#ifdef ASSERT
D
dcubed 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

/*
 * To avoid the most part of potential link errors
 * we link this program with -z nodefs .
 *
 * But for 'debug1' and 'fastdebug1' we still have to provide
 * a particular workaround for the following symbols bellow.
 * It will be good to find out a generic way in the future.
 */

#pragma weak tty
#pragma weak CMSExpAvgFactor

#if defined(i386) || defined(__i386) || defined(__amd64)
#pragma weak noreg
#endif /* i386 */

LIR_Opr LIR_OprFact::illegalOpr = (LIR_Opr) 0;

address StubRoutines::_call_stub_return_address = NULL;

StubQueue* AbstractInterpreter::_code = NULL;

D
drchase 已提交
87
#endif /* ASSERT */
D
dcubed 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
#endif /* COMPILER1 */

#define GEN_OFFS(Type,Name)                             \
  switch(gen_variant) {                                 \
  case GEN_OFFSET:                                      \
    printf("#define OFFSET_%-33s %ld\n",                 \
           #Type #Name, offset_of(Type, Name)); \
    break;                                              \
  case GEN_INDEX:                                       \
    printf("#define IDX_OFFSET_%-33s %d\n",             \
            #Type #Name, index++);                      \
    break;                                              \
  case GEN_TABLE:                                       \
    printf("\tOFFSET_%s,\n", #Type #Name);              \
    break;                                              \
  }

#define GEN_SIZE(Type)                                  \
  switch(gen_variant) {                                 \
  case GEN_OFFSET:                                      \
    printf("#define SIZE_%-35s %ld\n",                   \
            #Type, sizeof(Type));                       \
    break;                                              \
  case GEN_INDEX:                                       \
    printf("#define IDX_SIZE_%-35s %d\n",               \
            #Type, index++);                            \
    break;                                              \
  case GEN_TABLE:                                       \
    printf("\tSIZE_%s,\n", #Type);                      \
    break;                                              \
  }

#define GEN_VALUE(String,Value)                         \
  switch(gen_variant) {                                 \
  case GEN_OFFSET:                                      \
    printf("#define %-40s %d\n", #String, Value);       \
    break;                                              \
  case GEN_INDEX:                                       \
    printf("#define IDX_%-40s %d\n", #String, index++); \
    break;                                              \
  case GEN_TABLE:                                       \
    printf("\t" #String ",\n");                         \
    break;                                              \
  }

void gen_prologue(GEN_variant gen_variant) {
    const char *suffix;

    switch(gen_variant) {
      case GEN_OFFSET: suffix = ".h";        break;
      case GEN_INDEX:  suffix = "Index.h";   break;
      case GEN_TABLE:  suffix = ".cpp";      break;
    }

    printf("/*\n");
    printf(" * JvmOffsets%s !!!DO NOT EDIT!!! \n", suffix);
    printf(" * The generateJvmOffsets program generates this file!\n");
    printf(" */\n\n");
    switch(gen_variant) {

      case GEN_OFFSET:
      case GEN_INDEX:
        break;

      case GEN_TABLE:
        printf("#include \"JvmOffsets.h\"\n");
        printf("\n");
        printf("int __JvmOffsets[] = {\n");
        break;
    }
}

void gen_epilogue(GEN_variant gen_variant) {
    if (gen_variant != GEN_TABLE) {
        return;
    }
    printf("};\n\n");
    return;
}

int generateJvmOffsets(GEN_variant gen_variant) {
  int index = 0;        /* It is used to generate JvmOffsetsIndex.h */
  int pointer_size = sizeof(void *);
  int data_model = (pointer_size == 4) ? PR_MODEL_ILP32 : PR_MODEL_LP64;

  gen_prologue(gen_variant);

  GEN_VALUE(DATA_MODEL, data_model);
  GEN_VALUE(POINTER_SIZE, pointer_size);
#if defined(TIERED)
  GEN_VALUE(COMPILER, 3);
#elif COMPILER1
  GEN_VALUE(COMPILER, 1);
#elif COMPILER2
  GEN_VALUE(COMPILER, 2);
#else
  GEN_VALUE(COMPILER, 0);
#endif // COMPILER1 && COMPILER2
  printf("\n");

  GEN_OFFS(CollectedHeap, _reserved);
  GEN_OFFS(MemRegion, _start);
  GEN_OFFS(MemRegion, _word_size);
  GEN_SIZE(HeapWord);
  printf("\n");

  GEN_OFFS(VMStructEntry, typeName);
  GEN_OFFS(VMStructEntry, fieldName);
  GEN_OFFS(VMStructEntry, address);
  GEN_SIZE(VMStructEntry);
  printf("\n");

  GEN_VALUE(MAX_METHOD_CODE_SIZE, max_method_code_size);
#if defined(sparc) || defined(__sparc)
  GEN_VALUE(OFFSET_interpreter_frame_method, 2 * pointer_size);     /* L2 in saved window */
  GEN_VALUE(OFFSET_interpreter_frame_sender_sp, 13 * pointer_size); /* I5 in saved window */
  // Fake value for consistency. It is not going to be used.
  GEN_VALUE(OFFSET_interpreter_frame_bcx_offset, 0xFFFF);
#elif defined(i386) || defined(__i386) || defined(__amd64)
  GEN_VALUE(OFFSET_interpreter_frame_sender_sp, -1 * pointer_size);
  GEN_VALUE(OFFSET_interpreter_frame_method, -3 * pointer_size);
  GEN_VALUE(OFFSET_interpreter_frame_bcx_offset, -7 * pointer_size);
#endif

  GEN_OFFS(Klass, _name);
213
  GEN_OFFS(ConstantPool, _pool_holder);
D
dcubed 已提交
214 215 216 217 218 219 220
  printf("\n");

  GEN_VALUE(OFFSET_HeapBlockHeader_used, (int) offset_of(HeapBlock::Header, _used));
  GEN_OFFS(oopDesc, _metadata);
  printf("\n");

  GEN_VALUE(AccessFlags_NATIVE, JVM_ACC_NATIVE);
221
  GEN_VALUE(ConstMethod_has_linenumber_table, ConstMethod::_has_linenumber_table);
D
dcubed 已提交
222 223 224 225 226
  GEN_OFFS(AccessFlags, _flags);
  GEN_OFFS(Symbol, _length);
  GEN_OFFS(Symbol, _body);
  printf("\n");

227 228 229
  GEN_OFFS(Method, _constMethod);
  GEN_OFFS(Method, _constants);
  GEN_OFFS(Method, _access_flags);
D
dcubed 已提交
230 231
  printf("\n");

232 233 234 235
  GEN_OFFS(ConstMethod, _flags);
  GEN_OFFS(ConstMethod, _code_size);
  GEN_OFFS(ConstMethod, _name_index);
  GEN_OFFS(ConstMethod, _signature_index);
D
dcubed 已提交
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
  printf("\n");

  GEN_OFFS(CodeHeap, _memory);
  GEN_OFFS(CodeHeap, _segmap);
  GEN_OFFS(CodeHeap, _log2_segment_size);
  printf("\n");

  GEN_OFFS(VirtualSpace, _low_boundary);
  GEN_OFFS(VirtualSpace, _high_boundary);
  GEN_OFFS(VirtualSpace, _low);
  GEN_OFFS(VirtualSpace, _high);
  printf("\n");

  GEN_OFFS(CodeBlob, _name);
  GEN_OFFS(CodeBlob, _header_size);
  GEN_OFFS(CodeBlob, _content_offset);
  GEN_OFFS(CodeBlob, _code_offset);
  GEN_OFFS(CodeBlob, _data_offset);
  GEN_OFFS(CodeBlob, _frame_size);
  printf("\n");

  GEN_OFFS(nmethod, _method);
  GEN_OFFS(nmethod, _oops_offset);
  GEN_OFFS(nmethod, _scopes_data_offset);
  GEN_OFFS(nmethod, _scopes_pcs_offset);
  GEN_OFFS(nmethod, _handler_table_offset);
  GEN_OFFS(nmethod, _deoptimize_offset);
  GEN_OFFS(nmethod, _orig_pc_offset);

  GEN_OFFS(PcDesc, _pc_offset);
  GEN_OFFS(PcDesc, _scope_decode_offset);

  printf("\n");

270 271
  GEN_OFFS(NarrowPtrStruct, _base);
  GEN_OFFS(NarrowPtrStruct, _shift);
D
dcubed 已提交
272 273 274 275
  printf("\n");

  GEN_VALUE(SIZE_HeapBlockHeader, (int) sizeof(HeapBlock::Header));
  GEN_SIZE(oopDesc);
276
  GEN_SIZE(ConstantPool);
D
dcubed 已提交
277 278 279
  printf("\n");

  GEN_SIZE(PcDesc);
280 281
  GEN_SIZE(Method);
  GEN_SIZE(ConstMethod);
D
dcubed 已提交
282 283 284 285 286 287 288 289 290 291 292 293 294
  GEN_SIZE(nmethod);
  GEN_SIZE(CodeBlob);
  GEN_SIZE(BufferBlob);
  GEN_SIZE(SingletonBlob);
  GEN_SIZE(RuntimeStub);
  GEN_SIZE(SafepointBlob);

  gen_epilogue(gen_variant);
  printf("\n");

  fflush(stdout);
  return 0;
}