jvmciJavaClasses.cpp revision 9149:a8a8604f890f
12116Sjkh/* 22116Sjkh * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. 32116Sjkh * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 42116Sjkh * 52116Sjkh * This code is free software; you can redistribute it and/or modify it 62116Sjkh * under the terms of the GNU General Public License version 2 only, as 72116Sjkh * published by the Free Software Foundation. 82116Sjkh * 92116Sjkh * This code is distributed in the hope that it will be useful, but WITHOUT 102116Sjkh * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 112116Sjkh * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 122116Sjkh * version 2 for more details (a copy is included in the LICENSE file that 132116Sjkh * accompanied this code). 142116Sjkh * 152116Sjkh * You should have received a copy of the GNU General Public License version 162116Sjkh * 2 along with this work; if not, write to the Free Software Foundation, 172116Sjkh * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 182116Sjkh * 192116Sjkh * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 202116Sjkh * or visit www.oracle.com if you need additional information or have any 212116Sjkh * questions. 222116Sjkh */ 232116Sjkh 242116Sjkh#include "precompiled.hpp" 252116Sjkh#include "jvmci/jvmciJavaClasses.hpp" 262116Sjkh#include "runtime/jniHandles.hpp" 272116Sjkh#include "classfile/symbolTable.hpp" 282116Sjkh#include "memory/resourceArea.hpp" 292116Sjkh 302116Sjkh// This function is similar to javaClasses.cpp, it computes the field offset of a (static or instance) field. 312116Sjkh// It looks up the name and signature symbols without creating new ones, all the symbols of these classes need to be already loaded. 322116Sjkh 332116Sjkhvoid compute_offset(int &dest_offset, Klass* klass, const char* name, const char* signature, bool static_field) { 342116Sjkh InstanceKlass* ik = InstanceKlass::cast(klass); 352116Sjkh Symbol* name_symbol = SymbolTable::probe(name, (int)strlen(name)); 362116Sjkh Symbol* signature_symbol = SymbolTable::probe(signature, (int)strlen(signature)); 372116Sjkh if (name_symbol == NULL || signature_symbol == NULL) { 382116Sjkh#ifndef PRODUCT 392116Sjkh ik->print_on(tty); 402116Sjkh#endif 412116Sjkh fatal("symbol with name %s and signature %s was not found in symbol table (klass=%s)", name, signature, klass->name()->as_C_string()); 422116Sjkh } 432116Sjkh 442116Sjkh fieldDescriptor fd; 452116Sjkh if (!ik->find_field(name_symbol, signature_symbol, &fd)) { 462116Sjkh ResourceMark rm; 472116Sjkh fatal("Invalid layout of %s at %s", name_symbol->as_C_string(), ik->external_name()); 482116Sjkh } 492116Sjkh guarantee(fd.is_static() == static_field, "static/instance mismatch"); 502116Sjkh dest_offset = fd.offset(); 512116Sjkh assert(dest_offset != 0, "must be valid offset"); 522116Sjkh} 532116Sjkh 54// This piece of macro magic creates the contents of the jvmci_compute_offsets method that initializes the field indices of all the access classes. 55 56#define START_CLASS(name) { Klass* k = SystemDictionary::name##_klass(); assert(k != NULL, "Could not find class " #name ""); 57 58#define END_CLASS } 59 60#define FIELD(klass, name, signature, static_field) compute_offset(klass::_##name##_offset, k, #name, signature, static_field); 61#define CHAR_FIELD(klass, name) FIELD(klass, name, "C", false) 62#define INT_FIELD(klass, name) FIELD(klass, name, "I", false) 63#define BOOLEAN_FIELD(klass, name) FIELD(klass, name, "Z", false) 64#define LONG_FIELD(klass, name) FIELD(klass, name, "J", false) 65#define FLOAT_FIELD(klass, name) FIELD(klass, name, "F", false) 66#define OOP_FIELD(klass, name, signature) FIELD(klass, name, signature, false) 67#define STATIC_OOP_FIELD(klass, name, signature) FIELD(klass, name, signature, true) 68#define STATIC_INT_FIELD(klass, name) FIELD(klass, name, "I", true) 69#define STATIC_BOOLEAN_FIELD(klass, name) FIELD(klass, name, "Z", true) 70 71 72void JVMCIJavaClasses::compute_offsets() { 73 COMPILER_CLASSES_DO(START_CLASS, END_CLASS, CHAR_FIELD, INT_FIELD, BOOLEAN_FIELD, LONG_FIELD, FLOAT_FIELD, OOP_FIELD, OOP_FIELD, OOP_FIELD, STATIC_OOP_FIELD, STATIC_OOP_FIELD, STATIC_INT_FIELD, STATIC_BOOLEAN_FIELD) 74 guarantee(InstalledCode::_address_offset == sizeof(oopDesc), "codeBlob must be first field!"); 75} 76 77#define EMPTY0 78#define EMPTY1(x) 79#define EMPTY2(x,y) 80#define FIELD2(klass, name) int klass::_##name##_offset = 0; 81#define FIELD3(klass, name, sig) FIELD2(klass, name) 82 83COMPILER_CLASSES_DO(EMPTY1, EMPTY0, FIELD2, FIELD2, FIELD2, FIELD2, FIELD2, FIELD3, FIELD3, FIELD3, FIELD3, FIELD3, FIELD2, FIELD2) 84 85 86 87 88 89