1 /*
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
1385 Symbol* signature_symbol) {
1386 assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
1387 Thread* THREAD = Thread::current();
1388
1389 //Get the class of our object
1390 Klass* arg_klass = object->klass();
1391 //Turn it into an instance-klass
1392 InstanceKlass* ik = InstanceKlass::cast(arg_klass);
1393
1394 //Create symbols to look for in the class
1395 TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
1396 THREAD);
1397
1398 //To be filled in with an offset of the field we're looking for
1399 fieldDescriptor fd;
1400
1401 Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
1402 if (res == NULL) {
1403 tty->print_cr("Invalid layout of %s at %s", ik->external_name(),
1404 name_symbol->as_C_string());
1405 vm_exit_during_initialization("Invalid layout of preloaded class: use -XX:+TraceClassLoading to see the origin of the problem class");
1406 }
1407
1408 //fetch the field at the offset we've found
1409 int dest_offset = fd.offset();
1410
1411 return dest_offset;
1412 }
1413
1414
1415 const char* WhiteBox::lookup_jstring(const char* field_name, oop object) {
1416 int offset = offset_for_field(field_name, object,
1417 vmSymbols::string_signature());
1418 oop string = object->obj_field(offset);
1419 if (string == NULL) {
1420 return NULL;
1421 }
1422 const char* ret = java_lang_String::as_utf8_string(string);
1423 return ret;
1424 }
1425
|
1 /*
2 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
1385 Symbol* signature_symbol) {
1386 assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
1387 Thread* THREAD = Thread::current();
1388
1389 //Get the class of our object
1390 Klass* arg_klass = object->klass();
1391 //Turn it into an instance-klass
1392 InstanceKlass* ik = InstanceKlass::cast(arg_klass);
1393
1394 //Create symbols to look for in the class
1395 TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
1396 THREAD);
1397
1398 //To be filled in with an offset of the field we're looking for
1399 fieldDescriptor fd;
1400
1401 Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
1402 if (res == NULL) {
1403 tty->print_cr("Invalid layout of %s at %s", ik->external_name(),
1404 name_symbol->as_C_string());
1405 vm_exit_during_initialization("Invalid layout of preloaded class: use -Xlog:classload=info to see the origin of the problem class");
1406 }
1407
1408 //fetch the field at the offset we've found
1409 int dest_offset = fd.offset();
1410
1411 return dest_offset;
1412 }
1413
1414
1415 const char* WhiteBox::lookup_jstring(const char* field_name, oop object) {
1416 int offset = offset_for_field(field_name, object,
1417 vmSymbols::string_signature());
1418 oop string = object->obj_field(offset);
1419 if (string == NULL) {
1420 return NULL;
1421 }
1422 const char* ret = java_lang_String::as_utf8_string(string);
1423 return ret;
1424 }
1425
|