1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/os/bsd/dtrace/generateJvmOffsets.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,294 @@ 1.4 +/* 1.5 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +/* 1.29 + * This is to provide sanity check in jhelper.d which compares SCCS 1.30 + * versions of generateJvmOffsets.cpp used to create and extract 1.31 + * contents of __JvmOffsets[] table. 1.32 + * The __JvmOffsets[] table is located in generated JvmOffsets.cpp. 1.33 + * 1.34 + * GENOFFS_SCCS_VER 34 1.35 + */ 1.36 + 1.37 +#include "generateJvmOffsets.h" 1.38 + 1.39 +/* A workaround for private and protected fields */ 1.40 +#define private public 1.41 +#define protected public 1.42 + 1.43 +// not on macosx #include <proc_service.h> 1.44 +#include "code/codeBlob.hpp" 1.45 +#include "code/nmethod.hpp" 1.46 +#include "code/pcDesc.hpp" 1.47 +#include "gc_interface/collectedHeap.hpp" 1.48 +#include "memory/heap.hpp" 1.49 +#include "memory/memRegion.hpp" 1.50 +#include "memory/universe.hpp" 1.51 +#include "oops/constMethod.hpp" 1.52 +#include "oops/klass.hpp" 1.53 +#include "oops/method.hpp" 1.54 +#include "oops/oop.hpp" 1.55 +#include "oops/symbol.hpp" 1.56 +#include "runtime/virtualspace.hpp" 1.57 +#include "runtime/vmStructs.hpp" 1.58 +#include "utilities/accessFlags.hpp" 1.59 +#include "utilities/globalDefinitions.hpp" 1.60 + 1.61 +// These are defined somewhere for Solaris 1.62 +#define PR_MODEL_ILP32 1 1.63 +#define PR_MODEL_LP64 2 1.64 + 1.65 +#ifdef COMPILER1 1.66 +#ifdef ASSERT 1.67 + 1.68 +/* 1.69 + * To avoid the most part of potential link errors 1.70 + * we link this program with -z nodefs . 1.71 + * 1.72 + * But for 'debug1' and 'fastdebug1' we still have to provide 1.73 + * a particular workaround for the following symbols bellow. 1.74 + * It will be good to find out a generic way in the future. 1.75 + */ 1.76 + 1.77 +#pragma weak tty 1.78 +#pragma weak CMSExpAvgFactor 1.79 + 1.80 +#if defined(i386) || defined(__i386) || defined(__amd64) 1.81 +#pragma weak noreg 1.82 +#endif /* i386 */ 1.83 + 1.84 +LIR_Opr LIR_OprFact::illegalOpr = (LIR_Opr) 0; 1.85 + 1.86 +address StubRoutines::_call_stub_return_address = NULL; 1.87 + 1.88 +StubQueue* AbstractInterpreter::_code = NULL; 1.89 + 1.90 +#endif /* ASSERT */ 1.91 +#endif /* COMPILER1 */ 1.92 + 1.93 +#define GEN_OFFS(Type,Name) \ 1.94 + switch(gen_variant) { \ 1.95 + case GEN_OFFSET: \ 1.96 + printf("#define OFFSET_%-33s %ld\n", \ 1.97 + #Type #Name, offset_of(Type, Name)); \ 1.98 + break; \ 1.99 + case GEN_INDEX: \ 1.100 + printf("#define IDX_OFFSET_%-33s %d\n", \ 1.101 + #Type #Name, index++); \ 1.102 + break; \ 1.103 + case GEN_TABLE: \ 1.104 + printf("\tOFFSET_%s,\n", #Type #Name); \ 1.105 + break; \ 1.106 + } 1.107 + 1.108 +#define GEN_SIZE(Type) \ 1.109 + switch(gen_variant) { \ 1.110 + case GEN_OFFSET: \ 1.111 + printf("#define SIZE_%-35s %ld\n", \ 1.112 + #Type, sizeof(Type)); \ 1.113 + break; \ 1.114 + case GEN_INDEX: \ 1.115 + printf("#define IDX_SIZE_%-35s %d\n", \ 1.116 + #Type, index++); \ 1.117 + break; \ 1.118 + case GEN_TABLE: \ 1.119 + printf("\tSIZE_%s,\n", #Type); \ 1.120 + break; \ 1.121 + } 1.122 + 1.123 +#define GEN_VALUE(String,Value) \ 1.124 + switch(gen_variant) { \ 1.125 + case GEN_OFFSET: \ 1.126 + printf("#define %-40s %d\n", #String, Value); \ 1.127 + break; \ 1.128 + case GEN_INDEX: \ 1.129 + printf("#define IDX_%-40s %d\n", #String, index++); \ 1.130 + break; \ 1.131 + case GEN_TABLE: \ 1.132 + printf("\t" #String ",\n"); \ 1.133 + break; \ 1.134 + } 1.135 + 1.136 +void gen_prologue(GEN_variant gen_variant) { 1.137 + const char *suffix; 1.138 + 1.139 + switch(gen_variant) { 1.140 + case GEN_OFFSET: suffix = ".h"; break; 1.141 + case GEN_INDEX: suffix = "Index.h"; break; 1.142 + case GEN_TABLE: suffix = ".cpp"; break; 1.143 + } 1.144 + 1.145 + printf("/*\n"); 1.146 + printf(" * JvmOffsets%s !!!DO NOT EDIT!!! \n", suffix); 1.147 + printf(" * The generateJvmOffsets program generates this file!\n"); 1.148 + printf(" */\n\n"); 1.149 + switch(gen_variant) { 1.150 + 1.151 + case GEN_OFFSET: 1.152 + case GEN_INDEX: 1.153 + break; 1.154 + 1.155 + case GEN_TABLE: 1.156 + printf("#include \"JvmOffsets.h\"\n"); 1.157 + printf("\n"); 1.158 + printf("int __JvmOffsets[] = {\n"); 1.159 + break; 1.160 + } 1.161 +} 1.162 + 1.163 +void gen_epilogue(GEN_variant gen_variant) { 1.164 + if (gen_variant != GEN_TABLE) { 1.165 + return; 1.166 + } 1.167 + printf("};\n\n"); 1.168 + return; 1.169 +} 1.170 + 1.171 +int generateJvmOffsets(GEN_variant gen_variant) { 1.172 + int index = 0; /* It is used to generate JvmOffsetsIndex.h */ 1.173 + int pointer_size = sizeof(void *); 1.174 + int data_model = (pointer_size == 4) ? PR_MODEL_ILP32 : PR_MODEL_LP64; 1.175 + 1.176 + gen_prologue(gen_variant); 1.177 + 1.178 + GEN_VALUE(DATA_MODEL, data_model); 1.179 + GEN_VALUE(POINTER_SIZE, pointer_size); 1.180 +#if defined(TIERED) 1.181 + GEN_VALUE(COMPILER, 3); 1.182 +#elif COMPILER1 1.183 + GEN_VALUE(COMPILER, 1); 1.184 +#elif COMPILER2 1.185 + GEN_VALUE(COMPILER, 2); 1.186 +#else 1.187 + GEN_VALUE(COMPILER, 0); 1.188 +#endif // COMPILER1 && COMPILER2 1.189 + printf("\n"); 1.190 + 1.191 + GEN_OFFS(CollectedHeap, _reserved); 1.192 + GEN_OFFS(MemRegion, _start); 1.193 + GEN_OFFS(MemRegion, _word_size); 1.194 + GEN_SIZE(HeapWord); 1.195 + printf("\n"); 1.196 + 1.197 + GEN_OFFS(VMStructEntry, typeName); 1.198 + GEN_OFFS(VMStructEntry, fieldName); 1.199 + GEN_OFFS(VMStructEntry, address); 1.200 + GEN_SIZE(VMStructEntry); 1.201 + printf("\n"); 1.202 + 1.203 + GEN_VALUE(MAX_METHOD_CODE_SIZE, max_method_code_size); 1.204 +#if defined(sparc) || defined(__sparc) 1.205 + GEN_VALUE(OFFSET_interpreter_frame_method, 2 * pointer_size); /* L2 in saved window */ 1.206 + GEN_VALUE(OFFSET_interpreter_frame_sender_sp, 13 * pointer_size); /* I5 in saved window */ 1.207 + // Fake value for consistency. It is not going to be used. 1.208 + GEN_VALUE(OFFSET_interpreter_frame_bcx_offset, 0xFFFF); 1.209 +#elif defined(i386) || defined(__i386) || defined(__amd64) 1.210 + GEN_VALUE(OFFSET_interpreter_frame_sender_sp, -1 * pointer_size); 1.211 + GEN_VALUE(OFFSET_interpreter_frame_method, -3 * pointer_size); 1.212 + GEN_VALUE(OFFSET_interpreter_frame_bcx_offset, -7 * pointer_size); 1.213 +#endif 1.214 + 1.215 + GEN_OFFS(Klass, _name); 1.216 + GEN_OFFS(ConstantPool, _pool_holder); 1.217 + printf("\n"); 1.218 + 1.219 + GEN_VALUE(OFFSET_HeapBlockHeader_used, (int) offset_of(HeapBlock::Header, _used)); 1.220 + GEN_OFFS(oopDesc, _metadata); 1.221 + printf("\n"); 1.222 + 1.223 + GEN_VALUE(AccessFlags_NATIVE, JVM_ACC_NATIVE); 1.224 + GEN_VALUE(ConstMethod_has_linenumber_table, ConstMethod::_has_linenumber_table); 1.225 + GEN_OFFS(AccessFlags, _flags); 1.226 + GEN_OFFS(Symbol, _length); 1.227 + GEN_OFFS(Symbol, _body); 1.228 + printf("\n"); 1.229 + 1.230 + GEN_OFFS(Method, _constMethod); 1.231 + GEN_OFFS(Method, _constants); 1.232 + GEN_OFFS(Method, _access_flags); 1.233 + printf("\n"); 1.234 + 1.235 + GEN_OFFS(ConstMethod, _flags); 1.236 + GEN_OFFS(ConstMethod, _code_size); 1.237 + GEN_OFFS(ConstMethod, _name_index); 1.238 + GEN_OFFS(ConstMethod, _signature_index); 1.239 + printf("\n"); 1.240 + 1.241 + GEN_OFFS(CodeHeap, _memory); 1.242 + GEN_OFFS(CodeHeap, _segmap); 1.243 + GEN_OFFS(CodeHeap, _log2_segment_size); 1.244 + printf("\n"); 1.245 + 1.246 + GEN_OFFS(VirtualSpace, _low_boundary); 1.247 + GEN_OFFS(VirtualSpace, _high_boundary); 1.248 + GEN_OFFS(VirtualSpace, _low); 1.249 + GEN_OFFS(VirtualSpace, _high); 1.250 + printf("\n"); 1.251 + 1.252 + GEN_OFFS(CodeBlob, _name); 1.253 + GEN_OFFS(CodeBlob, _header_size); 1.254 + GEN_OFFS(CodeBlob, _content_offset); 1.255 + GEN_OFFS(CodeBlob, _code_offset); 1.256 + GEN_OFFS(CodeBlob, _data_offset); 1.257 + GEN_OFFS(CodeBlob, _frame_size); 1.258 + printf("\n"); 1.259 + 1.260 + GEN_OFFS(nmethod, _method); 1.261 + GEN_OFFS(nmethod, _oops_offset); 1.262 + GEN_OFFS(nmethod, _scopes_data_offset); 1.263 + GEN_OFFS(nmethod, _scopes_pcs_offset); 1.264 + GEN_OFFS(nmethod, _handler_table_offset); 1.265 + GEN_OFFS(nmethod, _deoptimize_offset); 1.266 + GEN_OFFS(nmethod, _orig_pc_offset); 1.267 + 1.268 + GEN_OFFS(PcDesc, _pc_offset); 1.269 + GEN_OFFS(PcDesc, _scope_decode_offset); 1.270 + 1.271 + printf("\n"); 1.272 + 1.273 + GEN_OFFS(NarrowPtrStruct, _base); 1.274 + GEN_OFFS(NarrowPtrStruct, _shift); 1.275 + printf("\n"); 1.276 + 1.277 + GEN_VALUE(SIZE_HeapBlockHeader, (int) sizeof(HeapBlock::Header)); 1.278 + GEN_SIZE(oopDesc); 1.279 + GEN_SIZE(ConstantPool); 1.280 + printf("\n"); 1.281 + 1.282 + GEN_SIZE(PcDesc); 1.283 + GEN_SIZE(Method); 1.284 + GEN_SIZE(ConstMethod); 1.285 + GEN_SIZE(nmethod); 1.286 + GEN_SIZE(CodeBlob); 1.287 + GEN_SIZE(BufferBlob); 1.288 + GEN_SIZE(SingletonBlob); 1.289 + GEN_SIZE(RuntimeStub); 1.290 + GEN_SIZE(SafepointBlob); 1.291 + 1.292 + gen_epilogue(gen_variant); 1.293 + printf("\n"); 1.294 + 1.295 + fflush(stdout); 1.296 + return 0; 1.297 +}