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