comparison src/share/vm/prims/whitebox.cpp @ 5978:51612f0c0a79

7148488: Whitebox tests for the Diagnostic Framework Parser Reviewed-by: brutisso, sla, mgerdin
author nloodin
date Thu, 15 Mar 2012 13:37:13 +0100
parents 2d503de963b3
children 5a1f452f8f90
comparison
equal deleted inserted replaced
5947:80fe40862b02 5978:51612f0c0a79
22 * 22 *
23 */ 23 */
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 26
27 #include "jni.h"
28
29 #include "memory/universe.hpp" 27 #include "memory/universe.hpp"
30 #include "oops/oop.inline.hpp" 28 #include "oops/oop.inline.hpp"
29
30 #include "classfile/symbolTable.hpp"
31
31 #include "prims/whitebox.hpp" 32 #include "prims/whitebox.hpp"
33 #include "prims/wbtestmethods/parserTests.hpp"
34
32 #include "runtime/interfaceSupport.hpp" 35 #include "runtime/interfaceSupport.hpp"
33 #include "runtime/os.hpp" 36 #include "runtime/os.hpp"
34 #include "utilities/debug.hpp" 37 #include "utilities/debug.hpp"
35 38
36 #ifndef SERIALGC 39 #ifndef SERIALGC
38 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" 41 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
39 #include "gc_implementation/g1/heapRegionRemSet.hpp" 42 #include "gc_implementation/g1/heapRegionRemSet.hpp"
40 #endif // !SERIALGC 43 #endif // !SERIALGC
41 44
42 bool WhiteBox::_used = false; 45 bool WhiteBox::_used = false;
43
44 // Entry macro to transition from JNI to VM state.
45
46 #define WB_ENTRY(result_type, header) JNI_ENTRY(result_type, header)
47 #define WB_END JNI_END
48
49 // Definitions of functions exposed via Whitebox API
50 46
51 WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj)) 47 WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj))
52 return (jlong)(void*)JNIHandles::resolve(obj); 48 return (jlong)(void*)JNIHandles::resolve(obj);
53 WB_END 49 WB_END
54 50
79 WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o)) 75 WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o))
80 return (jint)HeapRegion::GrainBytes; 76 return (jint)HeapRegion::GrainBytes;
81 WB_END 77 WB_END
82 #endif // !SERIALGC 78 #endif // !SERIALGC
83 79
80 //Some convenience methods to deal with objects from java
81 int WhiteBox::offset_for_field(const char* field_name, oop object,
82 Symbol* signature_symbol) {
83 assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
84 Thread* THREAD = Thread::current();
85
86 //Get the class of our object
87 klassOop arg_klass = object->klass();
88 //Turn it into an instance-klass
89 instanceKlass* ik = instanceKlass::cast(arg_klass);
90
91 //Create symbols to look for in the class
92 TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
93 THREAD);
94
95 //To be filled in with an offset of the field we're looking for
96 fieldDescriptor fd;
97
98 klassOop res = ik->find_field(name_symbol, signature_symbol, &fd);
99 if (res == NULL) {
100 tty->print_cr("Invalid layout of %s at %s", ik->external_name(),
101 name_symbol->as_C_string());
102 fatal("Invalid layout of preloaded class");
103 }
104
105 //fetch the field at the offset we've found
106 int dest_offset = fd.offset();
107
108 return dest_offset;
109 }
110
111
112 const char* WhiteBox::lookup_jstring(const char* field_name, oop object) {
113 int offset = offset_for_field(field_name, object,
114 vmSymbols::string_signature());
115 oop string = object->obj_field(offset);
116 const char* ret = java_lang_String::as_utf8_string(string);
117 return ret;
118 }
119
120 bool WhiteBox::lookup_bool(const char* field_name, oop object) {
121 int offset =
122 offset_for_field(field_name, object, vmSymbols::bool_signature());
123 bool ret = (object->bool_field(offset) == JNI_TRUE);
124 return ret;
125 }
126
127
84 #define CC (char*) 128 #define CC (char*)
85 129
86 static JNINativeMethod methods[] = { 130 static JNINativeMethod methods[] = {
87 {CC"getObjectAddress", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress }, 131 {CC"getObjectAddress", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress },
88 {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize }, 132 {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize },
133 {CC "parseCommandLine",
134 CC "(Ljava/lang/String;[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;",
135 (void*) &WB_ParseCommandLine
136 },
89 #ifndef SERIALGC 137 #ifndef SERIALGC
90 {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark}, 138 {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark},
91 {CC"g1IsHumongous", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous }, 139 {CC"g1IsHumongous", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous },
92 {CC"g1NumFreeRegions", CC"()J", (void*)&WB_G1NumFreeRegions }, 140 {CC"g1NumFreeRegions", CC"()J", (void*)&WB_G1NumFreeRegions },
93 {CC"g1RegionSize", CC"()I", (void*)&WB_G1RegionSize }, 141 {CC"g1RegionSize", CC"()I", (void*)&WB_G1RegionSize },