generateJvmOffsets.cpp revision 3602:da91efe96a93
150479Speter/*
2327Sjkh * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3327Sjkh * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4327Sjkh *
5327Sjkh * This code is free software; you can redistribute it and/or modify it
6327Sjkh * under the terms of the GNU General Public License version 2 only, as
7327Sjkh * published by the Free Software Foundation.
8327Sjkh *
9327Sjkh * This code is distributed in the hope that it will be useful, but WITHOUT
10327Sjkh * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11327Sjkh * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12327Sjkh * version 2 for more details (a copy is included in the LICENSE file that
13327Sjkh * accompanied this code).
14327Sjkh *
15327Sjkh * You should have received a copy of the GNU General Public License version
16327Sjkh * 2 along with this work; if not, write to the Free Software Foundation,
17327Sjkh * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18327Sjkh *
19327Sjkh * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20327Sjkh * or visit www.oracle.com if you need additional information or have any
21327Sjkh * questions.
22327Sjkh *
23327Sjkh */
24327Sjkh
25327Sjkh/*
2674699Ssobomax * This is to provide sanity check in jhelper.d which compares SCCS
2774699Ssobomax * versions of generateJvmOffsets.cpp used to create and extract
285399Sswallace * contents of __JvmOffsets[] table.
2967300Sdes * The __JvmOffsets[] table is located in generated JvmOffsets.cpp.
305399Sswallace *
315399Sswallace * GENOFFS_SCCS_VER 34
325399Sswallace */
335399Sswallace
345399Sswallace#include "generateJvmOffsets.h"
355399Sswallace
364996Sjkh/* A workaround for private and protected fields */
374996Sjkh#define private   public
384996Sjkh#define protected public
394996Sjkh
404996Sjkh// not on macosx #include <proc_service.h>
414996Sjkh#include "code/codeBlob.hpp"
424996Sjkh#include "code/nmethod.hpp"
434996Sjkh#include "code/pcDesc.hpp"
444996Sjkh#include "gc_interface/collectedHeap.hpp"
454996Sjkh#include "memory/heap.hpp"
464996Sjkh#include "memory/memRegion.hpp"
474996Sjkh#include "memory/universe.hpp"
4862775Ssobomax#include "oops/constMethod.hpp"
4967454Ssobomax#include "oops/klass.hpp"
5071965Sjkh#include "oops/method.hpp"
5184750Ssobomax#include "oops/oop.hpp"
52327Sjkh#include "oops/symbol.hpp"
5374699Ssobomax#include "runtime/virtualspace.hpp"
5474699Ssobomax#include "runtime/vmStructs.hpp"
5574699Ssobomax#include "utilities/accessFlags.hpp"
5674699Ssobomax#include "utilities/globalDefinitions.hpp"
5774699Ssobomax
5874699Ssobomax// These are defined somewhere for Solaris
5974699Ssobomax#define PR_MODEL_ILP32 1
6074699Ssobomax#define PR_MODEL_LP64  2
61327Sjkh
62411Sjkh#ifdef COMPILER1
63379Sjkh#if defined(DEBUG) || defined(FASTDEBUG)
6411780Sjkh
65392Sjkh/*
6696030Ssobomax * To avoid the most part of potential link errors
6772174Ssobomax * we link this program with -z nodefs .
6874699Ssobomax *
69327Sjkh * But for 'debug1' and 'fastdebug1' we still have to provide
7084745Ssobomax * a particular workaround for the following symbols bellow.
7184745Ssobomax * It will be good to find out a generic way in the future.
7284745Ssobomax */
7384745Ssobomax
7484745Ssobomax#pragma weak tty
7584745Ssobomax#pragma weak CMSExpAvgFactor
7684745Ssobomax
7784750Ssobomax#if defined(i386) || defined(__i386) || defined(__amd64)
78327Sjkh#pragma weak noreg
79327Sjkh#endif /* i386 */
80
81LIR_Opr LIR_OprFact::illegalOpr = (LIR_Opr) 0;
82
83address StubRoutines::_call_stub_return_address = NULL;
84
85StubQueue* AbstractInterpreter::_code = NULL;
86
87#endif /* defined(DEBUG) || defined(FASTDEBUG) */
88#endif /* COMPILER1 */
89
90#define GEN_OFFS(Type,Name)                             \
91  switch(gen_variant) {                                 \
92  case GEN_OFFSET:                                      \
93    printf("#define OFFSET_%-33s %ld\n",                 \
94           #Type #Name, offset_of(Type, Name)); \
95    break;                                              \
96  case GEN_INDEX:                                       \
97    printf("#define IDX_OFFSET_%-33s %d\n",             \
98            #Type #Name, index++);                      \
99    break;                                              \
100  case GEN_TABLE:                                       \
101    printf("\tOFFSET_%s,\n", #Type #Name);              \
102    break;                                              \
103  }
104
105#define GEN_SIZE(Type)                                  \
106  switch(gen_variant) {                                 \
107  case GEN_OFFSET:                                      \
108    printf("#define SIZE_%-35s %ld\n",                   \
109            #Type, sizeof(Type));                       \
110    break;                                              \
111  case GEN_INDEX:                                       \
112    printf("#define IDX_SIZE_%-35s %d\n",               \
113            #Type, index++);                            \
114    break;                                              \
115  case GEN_TABLE:                                       \
116    printf("\tSIZE_%s,\n", #Type);                      \
117    break;                                              \
118  }
119
120#define GEN_VALUE(String,Value)                         \
121  switch(gen_variant) {                                 \
122  case GEN_OFFSET:                                      \
123    printf("#define %-40s %d\n", #String, Value);       \
124    break;                                              \
125  case GEN_INDEX:                                       \
126    printf("#define IDX_%-40s %d\n", #String, index++); \
127    break;                                              \
128  case GEN_TABLE:                                       \
129    printf("\t" #String ",\n");                         \
130    break;                                              \
131  }
132
133void gen_prologue(GEN_variant gen_variant) {
134    const char *suffix;
135
136    switch(gen_variant) {
137      case GEN_OFFSET: suffix = ".h";        break;
138      case GEN_INDEX:  suffix = "Index.h";   break;
139      case GEN_TABLE:  suffix = ".cpp";      break;
140    }
141
142    printf("/*\n");
143    printf(" * JvmOffsets%s !!!DO NOT EDIT!!! \n", suffix);
144    printf(" * The generateJvmOffsets program generates this file!\n");
145    printf(" */\n\n");
146    switch(gen_variant) {
147
148      case GEN_OFFSET:
149      case GEN_INDEX:
150        break;
151
152      case GEN_TABLE:
153        printf("#include \"JvmOffsets.h\"\n");
154        printf("\n");
155        printf("int __JvmOffsets[] = {\n");
156        break;
157    }
158}
159
160void gen_epilogue(GEN_variant gen_variant) {
161    if (gen_variant != GEN_TABLE) {
162        return;
163    }
164    printf("};\n\n");
165    return;
166}
167
168int generateJvmOffsets(GEN_variant gen_variant) {
169  int index = 0;        /* It is used to generate JvmOffsetsIndex.h */
170  int pointer_size = sizeof(void *);
171  int data_model = (pointer_size == 4) ? PR_MODEL_ILP32 : PR_MODEL_LP64;
172
173  gen_prologue(gen_variant);
174
175  GEN_VALUE(DATA_MODEL, data_model);
176  GEN_VALUE(POINTER_SIZE, pointer_size);
177#if defined(TIERED)
178  GEN_VALUE(COMPILER, 3);
179#elif COMPILER1
180  GEN_VALUE(COMPILER, 1);
181#elif COMPILER2
182  GEN_VALUE(COMPILER, 2);
183#else
184  GEN_VALUE(COMPILER, 0);
185#endif // COMPILER1 && COMPILER2
186  printf("\n");
187
188  GEN_OFFS(CollectedHeap, _reserved);
189  GEN_OFFS(MemRegion, _start);
190  GEN_OFFS(MemRegion, _word_size);
191  GEN_SIZE(HeapWord);
192  printf("\n");
193
194  GEN_OFFS(VMStructEntry, typeName);
195  GEN_OFFS(VMStructEntry, fieldName);
196  GEN_OFFS(VMStructEntry, address);
197  GEN_SIZE(VMStructEntry);
198  printf("\n");
199
200  GEN_VALUE(MAX_METHOD_CODE_SIZE, max_method_code_size);
201#if defined(sparc) || defined(__sparc)
202  GEN_VALUE(OFFSET_interpreter_frame_method, 2 * pointer_size);     /* L2 in saved window */
203  GEN_VALUE(OFFSET_interpreter_frame_sender_sp, 13 * pointer_size); /* I5 in saved window */
204  // Fake value for consistency. It is not going to be used.
205  GEN_VALUE(OFFSET_interpreter_frame_bcx_offset, 0xFFFF);
206#elif defined(i386) || defined(__i386) || defined(__amd64)
207  GEN_VALUE(OFFSET_interpreter_frame_sender_sp, -1 * pointer_size);
208  GEN_VALUE(OFFSET_interpreter_frame_method, -3 * pointer_size);
209  GEN_VALUE(OFFSET_interpreter_frame_bcx_offset, -7 * pointer_size);
210#endif
211
212  GEN_OFFS(Klass, _name);
213  GEN_OFFS(ConstantPool, _pool_holder);
214  printf("\n");
215
216  GEN_VALUE(OFFSET_HeapBlockHeader_used, (int) offset_of(HeapBlock::Header, _used));
217  GEN_OFFS(oopDesc, _metadata);
218  printf("\n");
219
220  GEN_VALUE(AccessFlags_NATIVE, JVM_ACC_NATIVE);
221  GEN_VALUE(ConstMethod_has_linenumber_table, ConstMethod::_has_linenumber_table);
222  GEN_OFFS(AccessFlags, _flags);
223  GEN_OFFS(Symbol, _length);
224  GEN_OFFS(Symbol, _body);
225  printf("\n");
226
227  GEN_OFFS(Method, _constMethod);
228  GEN_OFFS(Method, _constants);
229  GEN_OFFS(Method, _access_flags);
230  printf("\n");
231
232  GEN_OFFS(ConstMethod, _flags);
233  GEN_OFFS(ConstMethod, _code_size);
234  GEN_OFFS(ConstMethod, _name_index);
235  GEN_OFFS(ConstMethod, _signature_index);
236  printf("\n");
237
238  GEN_OFFS(CodeHeap, _memory);
239  GEN_OFFS(CodeHeap, _segmap);
240  GEN_OFFS(CodeHeap, _log2_segment_size);
241  printf("\n");
242
243  GEN_OFFS(VirtualSpace, _low_boundary);
244  GEN_OFFS(VirtualSpace, _high_boundary);
245  GEN_OFFS(VirtualSpace, _low);
246  GEN_OFFS(VirtualSpace, _high);
247  printf("\n");
248
249  GEN_OFFS(CodeBlob, _name);
250  GEN_OFFS(CodeBlob, _header_size);
251  GEN_OFFS(CodeBlob, _content_offset);
252  GEN_OFFS(CodeBlob, _code_offset);
253  GEN_OFFS(CodeBlob, _data_offset);
254  GEN_OFFS(CodeBlob, _frame_size);
255  printf("\n");
256
257  GEN_OFFS(nmethod, _method);
258  GEN_OFFS(nmethod, _oops_offset);
259  GEN_OFFS(nmethod, _scopes_data_offset);
260  GEN_OFFS(nmethod, _scopes_pcs_offset);
261  GEN_OFFS(nmethod, _handler_table_offset);
262  GEN_OFFS(nmethod, _deoptimize_offset);
263  GEN_OFFS(nmethod, _orig_pc_offset);
264
265  GEN_OFFS(PcDesc, _pc_offset);
266  GEN_OFFS(PcDesc, _scope_decode_offset);
267
268  printf("\n");
269
270  GEN_OFFS(NarrowOopStruct, _base);
271  GEN_OFFS(NarrowOopStruct, _shift);
272  printf("\n");
273
274  GEN_VALUE(SIZE_HeapBlockHeader, (int) sizeof(HeapBlock::Header));
275  GEN_SIZE(oopDesc);
276  GEN_SIZE(ConstantPool);
277  printf("\n");
278
279  GEN_SIZE(PcDesc);
280  GEN_SIZE(Method);
281  GEN_SIZE(ConstMethod);
282  GEN_SIZE(nmethod);
283  GEN_SIZE(CodeBlob);
284  GEN_SIZE(BufferBlob);
285  GEN_SIZE(SingletonBlob);
286  GEN_SIZE(RuntimeStub);
287  GEN_SIZE(SafepointBlob);
288
289  gen_epilogue(gen_variant);
290  printf("\n");
291
292  fflush(stdout);
293  return 0;
294}
295