1 /* 2 * Copyright (c) 2003, 2015, 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 */ 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 // not on macosx #include <proc_service.h> 41 #include "code/codeBlob.hpp" 42 #include "code/nmethod.hpp" 43 #include "code/pcDesc.hpp" 44 #include "gc/shared/collectedHeap.hpp" 45 #include "memory/heap.hpp" 46 #include "memory/memRegion.hpp" 47 #include "memory/universe.hpp" 48 #include "memory/virtualspace.hpp" 49 #include "oops/constMethod.hpp" 50 #include "oops/klass.hpp" 51 #include "oops/method.hpp" 52 #include "oops/oop.hpp" 53 #include "oops/symbol.hpp" 54 #include "runtime/vmStructs.hpp" 55 #include "utilities/accessFlags.hpp" 56 #include "utilities/globalDefinitions.hpp" 57 58 // These are defined somewhere for Solaris 59 #define PR_MODEL_ILP32 1 60 #define PR_MODEL_LP64 2 61 62 #ifdef COMPILER1 63 #ifdef ASSERT 64 65 /* 66 * To avoid the most part of potential link errors 67 * we link this program with -z nodefs . 68 * 69 * But for 'debug1' and 'fastdebug1' we still have to provide 70 * a particular workaround for the following symbols below. 71 * It will be good to find out a generic way in the future. 72 */ 73 74 #pragma weak tty 75 #pragma weak CMSExpAvgFactor 76 77 #if defined(i386) || defined(__i386) || defined(__amd64) 78 #pragma weak noreg 79 #endif /* i386 */ 80 81 LIR_Opr LIR_OprFact::illegalOpr = (LIR_Opr) 0; 82 83 address StubRoutines::_call_stub_return_address = NULL; 84 85 StubQueue* AbstractInterpreter::_code = NULL; 86 87 #endif /* ASSERT */ 88 #endif /* COMPILER1 */ 89 90 #define GEN_OFFS_NAME(Type,Name,OutputType) \ 91 switch(gen_variant) { \ 92 case GEN_OFFSET: \ 93 printf("#define OFFSET_%-33s %ld\n", \ 94 #OutputType #Name, offset_of(Type, Name)); \ 95 break; \ 96 case GEN_INDEX: \ 97 printf("#define IDX_OFFSET_%-33s %d\n", \ 98 #OutputType #Name, index++); \ 99 break; \ 100 case GEN_TABLE: \ 101 printf("\tOFFSET_%s,\n", #OutputType #Name); \ 102 break; \ 103 } 104 105 #define GEN_OFFS(Type,Name) \ 106 GEN_OFFS_NAME(Type,Name,Type) 107 108 #define GEN_SIZE(Type) \ 109 switch(gen_variant) { \ 110 case GEN_OFFSET: \ 111 printf("#define SIZE_%-35s %ld\n", \ 112 #Type, sizeof(Type)); \ 113 break; \ 114 case GEN_INDEX: \ 115 printf("#define IDX_SIZE_%-35s %d\n", \ 116 #Type, index++); \ 117 break; \ 118 case GEN_TABLE: \ 119 printf("\tSIZE_%s,\n", #Type); \ 120 break; \ 121 } 122 123 #define GEN_VALUE(String,Value) \ 124 switch(gen_variant) { \ 125 case GEN_OFFSET: \ 126 printf("#define %-40s %d\n", #String, Value); \ 127 break; \ 128 case GEN_INDEX: \ 129 printf("#define IDX_%-40s %d\n", #String, index++); \ 130 break; \ 131 case GEN_TABLE: \ 132 printf("\t" #String ",\n"); \ 133 break; \ 134 } 135 136 void gen_prologue(GEN_variant gen_variant) { 137 const char *suffix; 138 139 switch(gen_variant) { 140 case GEN_OFFSET: suffix = ".h"; break; 141 case GEN_INDEX: suffix = "Index.h"; break; 142 case GEN_TABLE: suffix = ".cpp"; break; 143 } 144 145 printf("/*\n"); 146 printf(" * JvmOffsets%s !!!DO NOT EDIT!!! \n", suffix); 147 printf(" * The generateJvmOffsets program generates this file!\n"); 148 printf(" */\n\n"); 149 switch(gen_variant) { 150 151 case GEN_OFFSET: 152 case GEN_INDEX: 153 break; 154 155 case GEN_TABLE: 156 printf("#include \"JvmOffsets.h\"\n"); 157 printf("\n"); 158 printf("int __JvmOffsets[] = {\n"); 159 break; 160 } 161 } 162 163 void gen_epilogue(GEN_variant gen_variant) { 164 if (gen_variant != GEN_TABLE) { 165 return; 166 } 167 printf("};\n\n"); 168 return; 169 } 170 171 int generateJvmOffsets(GEN_variant gen_variant) { 172 int index = 0; /* It is used to generate JvmOffsetsIndex.h */ 173 int pointer_size = sizeof(void *); 174 int data_model = (pointer_size == 4) ? PR_MODEL_ILP32 : PR_MODEL_LP64; 175 176 gen_prologue(gen_variant); 177 178 GEN_VALUE(DATA_MODEL, data_model); 179 GEN_VALUE(POINTER_SIZE, pointer_size); 180 #if defined(TIERED) 181 GEN_VALUE(COMPILER, 3); 182 #elif COMPILER1 183 GEN_VALUE(COMPILER, 1); 184 #elif COMPILER2 185 GEN_VALUE(COMPILER, 2); 186 #else 187 GEN_VALUE(COMPILER, 0); 188 #endif // COMPILER1 && COMPILER2 189 printf("\n"); 190 191 GEN_OFFS(CollectedHeap, _reserved); 192 GEN_OFFS(MemRegion, _start); 193 GEN_OFFS(MemRegion, _word_size); 194 GEN_SIZE(HeapWord); 195 printf("\n"); 196 197 GEN_OFFS(VMStructEntry, typeName); 198 GEN_OFFS(VMStructEntry, fieldName); 199 GEN_OFFS(VMStructEntry, address); 200 GEN_SIZE(VMStructEntry); 201 printf("\n"); 202 203 GEN_VALUE(MAX_METHOD_CODE_SIZE, max_method_code_size); 204 #if defined(sparc) || defined(__sparc) 205 GEN_VALUE(OFFSET_interpreter_frame_method, 2 * pointer_size); /* L2 in saved window */ 206 GEN_VALUE(OFFSET_interpreter_frame_sender_sp, 13 * pointer_size); /* I5 in saved window */ 207 // Fake value for consistency. It is not going to be used. 208 GEN_VALUE(OFFSET_interpreter_frame_bcp_offset, 0xFFFF); 209 #elif defined(i386) || defined(__i386) || defined(__amd64) 210 GEN_VALUE(OFFSET_interpreter_frame_sender_sp, -1 * pointer_size); 211 GEN_VALUE(OFFSET_interpreter_frame_method, -3 * pointer_size); 212 GEN_VALUE(OFFSET_interpreter_frame_bcp_offset, -7 * pointer_size); 213 #endif 214 215 GEN_OFFS(Klass, _name); 216 GEN_OFFS(ConstantPool, _pool_holder); 217 printf("\n"); 218 219 GEN_VALUE(OFFSET_HeapBlockHeader_used, (int) offset_of(HeapBlock::Header, _used)); 220 GEN_OFFS(oopDesc, _metadata); 221 printf("\n"); 222 223 GEN_VALUE(AccessFlags_NATIVE, JVM_ACC_NATIVE); 224 GEN_VALUE(ConstMethod_has_linenumber_table, ConstMethod::_has_linenumber_table); 225 GEN_OFFS(AccessFlags, _flags); 226 GEN_OFFS(Symbol, _length); 227 GEN_OFFS(Symbol, _body); 228 printf("\n"); 229 230 GEN_OFFS(Method, _constMethod); 231 GEN_OFFS(Method, _constants); 232 GEN_OFFS(Method, _access_flags); 233 printf("\n"); 234 235 GEN_OFFS(ConstMethod, _flags); 236 GEN_OFFS(ConstMethod, _code_size); 237 GEN_OFFS(ConstMethod, _name_index); 238 GEN_OFFS(ConstMethod, _signature_index); 239 printf("\n"); 240 241 GEN_OFFS(CodeHeap, _memory); 242 GEN_OFFS(CodeHeap, _segmap); 243 GEN_OFFS(CodeHeap, _log2_segment_size); 244 printf("\n"); 245 246 GEN_OFFS(VirtualSpace, _low_boundary); 247 GEN_OFFS(VirtualSpace, _high_boundary); 248 GEN_OFFS(VirtualSpace, _low); 249 GEN_OFFS(VirtualSpace, _high); 250 printf("\n"); 251 252 /* We need to use different names here because of the template parameter */ 253 GEN_OFFS_NAME(GrowableArray<CodeHeap*>, _data, GrowableArray_CodeHeap); 254 GEN_OFFS_NAME(GrowableArray<CodeHeap*>, _len, GrowableArray_CodeHeap); 255 printf("\n"); 256 257 GEN_OFFS(CodeBlob, _name); 258 GEN_OFFS(CodeBlob, _header_size); 259 GEN_OFFS(CodeBlob, _content_offset); 260 GEN_OFFS(CodeBlob, _code_offset); 261 GEN_OFFS(CodeBlob, _data_offset); 262 GEN_OFFS(CodeBlob, _frame_size); 263 printf("\n"); 264 265 GEN_OFFS(nmethod, _method); 266 GEN_OFFS(nmethod, _dependencies_offset); 267 GEN_OFFS(nmethod, _oops_offset); 268 GEN_OFFS(nmethod, _scopes_data_offset); 269 GEN_OFFS(nmethod, _scopes_pcs_offset); 270 GEN_OFFS(nmethod, _handler_table_offset); 271 GEN_OFFS(nmethod, _deoptimize_offset); 272 GEN_OFFS(nmethod, _orig_pc_offset); 273 274 GEN_OFFS(PcDesc, _pc_offset); 275 GEN_OFFS(PcDesc, _scope_decode_offset); 276 277 printf("\n"); 278 279 GEN_OFFS(NarrowPtrStruct, _base); 280 GEN_OFFS(NarrowPtrStruct, _shift); 281 printf("\n"); 282 283 GEN_VALUE(SIZE_HeapBlockHeader, (int) sizeof(HeapBlock::Header)); 284 GEN_SIZE(oopDesc); 285 GEN_SIZE(ConstantPool); 286 printf("\n"); 287 288 GEN_SIZE(PcDesc); 289 GEN_SIZE(Method); 290 GEN_SIZE(ConstMethod); 291 GEN_SIZE(nmethod); 292 GEN_SIZE(CodeBlob); 293 GEN_SIZE(BufferBlob); 294 GEN_SIZE(SingletonBlob); 295 GEN_SIZE(RuntimeStub); 296 GEN_SIZE(SafepointBlob); 297 298 gen_epilogue(gen_variant); 299 printf("\n"); 300 301 fflush(stdout); 302 return 0; 303 }