1 #ifdef USE_PRAGMA_IDENT_SRC
   2 #pragma ident "@(#)generateJvmOffsets.cpp       1.33 07/05/05 17:04:38 JVM"
   3 #endif
   4 /*
   5  * Copyright 2003-2007 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  
  26  */
  27 
  28 /*
  29  * This is to provide sanity check in jhelper.d which compares SCCS
  30  * versions of generateJvmOffsets.cpp used to create and extract
  31  * contents of __JvmOffsets[] table.
  32  * The __JvmOffsets[] table is located in generated JvmOffsets.cpp.
  33  *
  34  * GENOFFS_SCCS_VER 33
  35  */
  36 
  37 #include "generateJvmOffsets.h"
  38 
  39 /* A workaround for private and protected fields */
  40 #define private   public
  41 #define protected public
  42 
  43 #include <proc_service.h>
  44 #include "incls/_precompiled.incl"
  45 #include "incls/_vmStructs.cpp.incl"
  46 
  47 #ifdef COMPILER1
  48 #if defined(DEBUG) || defined(FASTDEBUG)
  49 
  50 /*
  51  * To avoid the most part of potential link errors
  52  * we link this program with -z nodefs .
  53  *
  54  * But for 'debug1' and 'fastdebug1' we still have to provide
  55  * a particular workaround for the following symbols bellow.
  56  * It will be good to find out a generic way in the future.
  57  */
  58 
  59 #pragma weak tty
  60 #pragma weak CMSExpAvgFactor
  61 
  62 #if defined(i386) || defined(__i386) || defined(__amd64)
  63 #pragma weak noreg
  64 #endif /* i386 */
  65 
  66 LIR_Opr LIR_OprFact::illegalOpr = (LIR_Opr) 0;
  67 
  68 address StubRoutines::_call_stub_return_address = NULL; 
  69 
  70 StubQueue* AbstractInterpreter::_code = NULL;
  71 
  72 #endif /* defined(DEBUG) || defined(FASTDEBUG) */
  73 #endif /* COMPILER1 */
  74 
  75 #define GEN_OFFS(Type,Name)                             \
  76   switch(gen_variant) {                                 \
  77   case GEN_OFFSET:                                      \
  78     printf("#define OFFSET_%-33s %d\n",                 \
  79             #Type #Name, offset_of(Type, Name));        \
  80     break;                                              \
  81   case GEN_INDEX:                                       \
  82     printf("#define IDX_OFFSET_%-33s %d\n",             \
  83             #Type #Name, index++);                      \
  84     break;                                              \
  85   case GEN_TABLE:                                       \
  86     printf("\tOFFSET_%s,\n", #Type #Name);              \
  87     break;                                              \
  88   }
  89 
  90 #define GEN_SIZE(Type)                                  \
  91   switch(gen_variant) {                                 \
  92   case GEN_OFFSET:                                      \
  93     printf("#define SIZE_%-35s %d\n",                   \
  94             #Type, sizeof(Type));                       \
  95     break;                                              \
  96   case GEN_INDEX:                                       \
  97     printf("#define IDX_SIZE_%-35s %d\n",               \
  98             #Type, index++);                            \
  99     break;                                              \
 100   case GEN_TABLE:                                       \
 101     printf("\tSIZE_%s,\n", #Type);                      \
 102     break;                                              \
 103   }
 104 
 105 #define GEN_VALUE(String,Value)                         \
 106   switch(gen_variant) {                                 \
 107   case GEN_OFFSET:                                      \
 108     printf("#define %-40s %d\n", #String, Value);       \
 109     break;                                              \
 110   case GEN_INDEX:                                       \
 111     printf("#define IDX_%-40s %d\n", #String, index++); \
 112     break;                                              \
 113   case GEN_TABLE:                                       \
 114     printf("\t" #String ",\n");                         \
 115     break;                                              \
 116   }
 117 
 118 void gen_prologue(GEN_variant gen_variant) {
 119     const char *suffix;
 120 
 121     switch(gen_variant) {
 122       case GEN_OFFSET: suffix = ".h";        break;
 123       case GEN_INDEX:  suffix = "Index.h";   break;
 124       case GEN_TABLE:  suffix = ".cpp";      break;
 125     }
 126 
 127     printf("/*\n");
 128     printf(" * JvmOffsets%s !!!DO NOT EDIT!!! \n", suffix);
 129     printf(" * The generateJvmOffsets program generates this file!\n");
 130     printf(" */\n\n");
 131     switch(gen_variant) {
 132 
 133       case GEN_OFFSET:
 134       case GEN_INDEX:
 135         break;
 136 
 137       case GEN_TABLE:
 138         printf("#include \"JvmOffsets.h\"\n");
 139         printf("\n");
 140         printf("int __JvmOffsets[] = {\n");
 141         break;
 142     }
 143 }
 144 
 145 void gen_epilogue(GEN_variant gen_variant) {
 146     if (gen_variant != GEN_TABLE) {
 147         return;
 148     }
 149     printf("};\n\n");
 150     return;
 151 }
 152 
 153 int generateJvmOffsets(GEN_variant gen_variant) {
 154   int index = 0;        /* It is used to generate JvmOffsetsIndex.h */
 155   int pointer_size = sizeof(void *);
 156   int data_model = (pointer_size == 4) ? PR_MODEL_ILP32 : PR_MODEL_LP64;
 157 
 158   gen_prologue(gen_variant);
 159 
 160   GEN_VALUE(DATA_MODEL, data_model);
 161   GEN_VALUE(POINTER_SIZE, pointer_size);
 162 #if defined(TIERED)
 163   GEN_VALUE(COMPILER, 3);
 164 #elif COMPILER1
 165   GEN_VALUE(COMPILER, 1);
 166 #elif COMPILER2
 167   GEN_VALUE(COMPILER, 2);
 168 #else
 169   GEN_VALUE(COMPILER, 0);
 170 #endif // COMPILER1 && COMPILER2
 171   printf("\n");
 172 
 173   GEN_OFFS(CollectedHeap, _reserved);
 174   GEN_OFFS(MemRegion, _start);
 175   GEN_OFFS(MemRegion, _word_size);
 176   GEN_SIZE(HeapWord);
 177   printf("\n");
 178 
 179   GEN_OFFS(VMStructEntry, typeName);
 180   GEN_OFFS(VMStructEntry, fieldName);
 181   GEN_OFFS(VMStructEntry, address);
 182   GEN_SIZE(VMStructEntry);
 183   printf("\n");
 184 
 185   GEN_VALUE(MAX_METHOD_CODE_SIZE, max_method_code_size);
 186 #if defined(sparc) || defined(__sparc)
 187   GEN_VALUE(OFFSET_interpreter_frame_method, 2 * pointer_size);     /* L2 in saved window */
 188   GEN_VALUE(OFFSET_interpreter_frame_sender_sp, 13 * pointer_size); /* I5 in saved window */
 189   // Fake value for consistency. It is not going to be used.
 190   GEN_VALUE(OFFSET_interpreter_frame_bcx_offset, 0xFFFF);
 191 #elif defined(i386) || defined(__i386) || defined(__amd64)
 192   GEN_VALUE(OFFSET_interpreter_frame_sender_sp, -1 * pointer_size);
 193   GEN_VALUE(OFFSET_interpreter_frame_method, -3 * pointer_size);
 194   GEN_VALUE(OFFSET_interpreter_frame_bcx_offset, -7 * pointer_size);
 195 #endif
 196 
 197   GEN_OFFS(Klass, _name);
 198   GEN_OFFS(constantPoolOopDesc, _pool_holder);
 199   printf("\n");
 200 
 201   GEN_VALUE(OFFSET_HeapBlockHeader_used, offset_of(HeapBlock::Header, _used));
 202   GEN_OFFS(oopDesc, _klass);
 203   printf("\n");
 204 
 205   GEN_VALUE(AccessFlags_NATIVE, JVM_ACC_NATIVE);
 206   GEN_VALUE(constMethodOopDesc_has_linenumber_table, constMethodOopDesc::_has_linenumber_table);
 207   GEN_OFFS(AccessFlags, _flags);
 208   GEN_OFFS(symbolOopDesc, _length);
 209   GEN_OFFS(symbolOopDesc, _body);
 210   printf("\n");
 211 
 212   GEN_OFFS(methodOopDesc, _constMethod);
 213   GEN_OFFS(methodOopDesc, _constants);
 214   GEN_OFFS(methodOopDesc, _access_flags);
 215   printf("\n");
 216 
 217   GEN_OFFS(constMethodOopDesc, _flags);
 218   GEN_OFFS(constMethodOopDesc, _code_size);
 219   GEN_OFFS(constMethodOopDesc, _name_index);
 220   GEN_OFFS(constMethodOopDesc, _signature_index);
 221   printf("\n");
 222 
 223   GEN_OFFS(CodeHeap, _memory);
 224   GEN_OFFS(CodeHeap, _segmap);
 225   GEN_OFFS(CodeHeap, _log2_segment_size);
 226   printf("\n");
 227 
 228   GEN_OFFS(VirtualSpace, _low_boundary);
 229   GEN_OFFS(VirtualSpace, _high_boundary);
 230   GEN_OFFS(VirtualSpace, _low);
 231   GEN_OFFS(VirtualSpace, _high);
 232   printf("\n");
 233 
 234   GEN_OFFS(CodeBlob, _name);
 235   GEN_OFFS(CodeBlob, _header_size);
 236   GEN_OFFS(CodeBlob, _instructions_offset);
 237   GEN_OFFS(CodeBlob, _data_offset);
 238   GEN_OFFS(CodeBlob, _oops_offset);
 239   GEN_OFFS(CodeBlob, _oops_length);
 240   GEN_OFFS(CodeBlob, _frame_size);
 241   printf("\n");
 242 
 243   GEN_OFFS(nmethod, _method);
 244   GEN_OFFS(nmethod, _scopes_data_offset);
 245   GEN_OFFS(nmethod, _scopes_pcs_offset);
 246   GEN_OFFS(nmethod, _handler_table_offset);
 247   GEN_OFFS(nmethod, _deoptimize_offset);
 248   GEN_OFFS(nmethod, _orig_pc_offset);
 249 
 250   GEN_OFFS(PcDesc, _pc_offset);
 251   GEN_OFFS(PcDesc, _scope_decode_offset);
 252 
 253   printf("\n");
 254 
 255   GEN_VALUE(SIZE_HeapBlockHeader, sizeof(HeapBlock::Header));
 256   GEN_SIZE(oopDesc);
 257   GEN_SIZE(constantPoolOopDesc);
 258   printf("\n");
 259 
 260   GEN_SIZE(PcDesc);
 261   GEN_SIZE(methodOopDesc);
 262   GEN_SIZE(constMethodOopDesc);
 263   GEN_SIZE(nmethod);
 264   GEN_SIZE(CodeBlob);
 265   GEN_SIZE(BufferBlob);
 266   GEN_SIZE(SingletonBlob);
 267   GEN_SIZE(RuntimeStub);
 268   GEN_SIZE(SafepointBlob);
 269 
 270   gen_epilogue(gen_variant);
 271   printf("\n");
 272 
 273   fflush(stdout);
 274   return 0;
 275 }