aoqi@0: /* aoqi@0: * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_RUNTIME_VMSTRUCTS_HPP aoqi@0: #define SHARE_VM_RUNTIME_VMSTRUCTS_HPP aoqi@0: aoqi@0: #include "utilities/debug.hpp" aoqi@0: #ifdef COMPILER1 aoqi@0: #include "c1/c1_Runtime1.hpp" aoqi@0: #endif aoqi@0: aoqi@0: // This table encapsulates the debugging information required by the aoqi@0: // serviceability agent in order to run. Specifically, we need to aoqi@0: // understand the layout of certain C data structures (offsets, in aoqi@0: // bytes, of their fields.) aoqi@0: // aoqi@0: // There are alternatives for the design of this mechanism, including aoqi@0: // parsing platform-specific debugging symbols from a debug build into aoqi@0: // a program database. While this current mechanism can be considered aoqi@0: // to be a workaround for the inability to debug arbitrary C and C++ aoqi@0: // programs at the present time, it does have certain advantages. aoqi@0: // First, it is platform-independent, which will vastly simplify the aoqi@0: // initial bringup of the system both now and on future platforms. aoqi@0: // Second, it is embedded within the VM, as opposed to being in a aoqi@0: // separate program database; experience has shown that whenever aoqi@0: // portions of a system are decoupled, version skew is problematic. aoqi@0: // Third, generating a program database, for example for a product aoqi@0: // build, would probably require two builds to be done: the desired aoqi@0: // product build as well as an intermediary build with the PRODUCT aoqi@0: // flag turned on but also compiled with -g, leading to a doubling of aoqi@0: // the time required to get a serviceability agent-debuggable product aoqi@0: // build. Fourth, and very significantly, this table probably aoqi@0: // preserves more information about field types than stabs do; for aoqi@0: // example, it preserves the fact that a field is a "jlong" rather aoqi@0: // than transforming the type according to the typedef in jni_md.h, aoqi@0: // which allows the Java-side code to identify "Java-sized" fields in aoqi@0: // C++ data structures. If the symbol parsing mechanism was redone aoqi@0: // using stabs, it might still be necessary to have a table somewhere aoqi@0: // containing this information. aoqi@0: // aoqi@0: // Do not change the sizes or signedness of the integer values in aoqi@0: // these data structures; they are fixed over in the serviceability aoqi@0: // agent's Java code (for bootstrapping). aoqi@0: aoqi@0: typedef struct { aoqi@0: const char* typeName; // The type name containing the given field (example: "Klass") aoqi@0: const char* fieldName; // The field name within the type (example: "_name") aoqi@0: const char* typeString; // Quoted name of the type of this field (example: "Symbol*"; aoqi@0: // parsed in Java to ensure type correctness aoqi@0: int32_t isStatic; // Indicates whether following field is an offset or an address aoqi@0: uint64_t offset; // Offset of field within structure; only used for nonstatic fields aoqi@0: void* address; // Address of field; only used for static fields aoqi@0: // ("offset" can not be reused because of apparent SparcWorks compiler bug aoqi@0: // in generation of initializer data) aoqi@0: } VMStructEntry; aoqi@0: aoqi@0: typedef struct { aoqi@0: const char* typeName; // Type name (example: "Method") aoqi@0: const char* superclassName; // Superclass name, or null if none (example: "oopDesc") aoqi@0: int32_t isOopType; // Does this type represent an oop typedef? (i.e., "Method*" or aoqi@0: // "Klass*", but NOT "Method") aoqi@0: int32_t isIntegerType; // Does this type represent an integer type (of arbitrary size)? aoqi@0: int32_t isUnsigned; // If so, is it unsigned? aoqi@0: uint64_t size; // Size, in bytes, of the type aoqi@0: } VMTypeEntry; aoqi@0: aoqi@0: typedef struct { aoqi@0: const char* name; // Name of constant (example: "_thread_in_native") aoqi@0: int32_t value; // Value of constant aoqi@0: } VMIntConstantEntry; aoqi@0: aoqi@0: typedef struct { aoqi@0: const char* name; // Name of constant (example: "_thread_in_native") aoqi@0: uint64_t value; // Value of constant aoqi@0: } VMLongConstantEntry; aoqi@0: aoqi@0: // This class is a friend of most classes, to be able to access aoqi@0: // private fields aoqi@0: class VMStructs { aoqi@0: public: aoqi@0: // The last entry is identified over in the serviceability agent by aoqi@0: // the fact that it has a NULL fieldName aoqi@0: static VMStructEntry localHotSpotVMStructs[]; aoqi@0: aoqi@0: // The last entry is identified over in the serviceability agent by aoqi@0: // the fact that it has a NULL typeName aoqi@0: static VMTypeEntry localHotSpotVMTypes[]; aoqi@0: aoqi@0: // Table of integer constants required by the serviceability agent. aoqi@0: // The last entry is identified over in the serviceability agent by aoqi@0: // the fact that it has a NULL typeName aoqi@0: static VMIntConstantEntry localHotSpotVMIntConstants[]; aoqi@0: aoqi@0: // Table of long constants required by the serviceability agent. aoqi@0: // The last entry is identified over in the serviceability agent by aoqi@0: // the fact that it has a NULL typeName aoqi@0: static VMLongConstantEntry localHotSpotVMLongConstants[]; aoqi@0: aoqi@0: // This is used to run any checking code necessary for validation of aoqi@0: // the data structure (debug build only) aoqi@0: static void init(); aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: // Execute unit tests aoqi@0: static void test(); aoqi@0: #endif aoqi@0: aoqi@0: private: aoqi@0: // Look up a type in localHotSpotVMTypes using strcmp() (debug build only). aoqi@0: // Returns 1 if found, 0 if not. aoqi@0: // debug_only(static int findType(const char* typeName);) aoqi@0: static int findType(const char* typeName); aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_RUNTIME_VMSTRUCTS_HPP