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 *
1390 Symbol* signature_symbol) {
1391 assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
1392 Thread* THREAD = Thread::current();
1393
1394 //Get the class of our object
1395 Klass* arg_klass = object->klass();
1396 //Turn it into an instance-klass
1397 InstanceKlass* ik = InstanceKlass::cast(arg_klass);
1398
1399 //Create symbols to look for in the class
1400 TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
1401 THREAD);
1402
1403 //To be filled in with an offset of the field we're looking for
1404 fieldDescriptor fd;
1405
1406 Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
1407 if (res == NULL) {
1408 tty->print_cr("Invalid layout of %s at %s", ik->external_name(),
1409 name_symbol->as_C_string());
1410 vm_exit_during_initialization("Invalid layout of preloaded class: use -XX:+TraceClassLoading to see the origin of the problem class");
1411 }
1412
1413 //fetch the field at the offset we've found
1414 int dest_offset = fd.offset();
1415
1416 return dest_offset;
1417 }
1418
1419
1420 const char* WhiteBox::lookup_jstring(const char* field_name, oop object) {
1421 int offset = offset_for_field(field_name, object,
1422 vmSymbols::string_signature());
1423 oop string = object->obj_field(offset);
1424 if (string == NULL) {
1425 return NULL;
1426 }
1427 const char* ret = java_lang_String::as_utf8_string(string);
1428 return ret;
1429 }
1430
|
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 *
1390 Symbol* signature_symbol) {
1391 assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
1392 Thread* THREAD = Thread::current();
1393
1394 //Get the class of our object
1395 Klass* arg_klass = object->klass();
1396 //Turn it into an instance-klass
1397 InstanceKlass* ik = InstanceKlass::cast(arg_klass);
1398
1399 //Create symbols to look for in the class
1400 TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
1401 THREAD);
1402
1403 //To be filled in with an offset of the field we're looking for
1404 fieldDescriptor fd;
1405
1406 Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
1407 if (res == NULL) {
1408 tty->print_cr("Invalid layout of %s at %s", ik->external_name(),
1409 name_symbol->as_C_string());
1410 vm_exit_during_initialization("Invalid layout of preloaded class: use -Xlog:classload=info to see the origin of the problem class");
1411 }
1412
1413 //fetch the field at the offset we've found
1414 int dest_offset = fd.offset();
1415
1416 return dest_offset;
1417 }
1418
1419
1420 const char* WhiteBox::lookup_jstring(const char* field_name, oop object) {
1421 int offset = offset_for_field(field_name, object,
1422 vmSymbols::string_signature());
1423 oop string = object->obj_field(offset);
1424 if (string == NULL) {
1425 return NULL;
1426 }
1427 const char* ret = java_lang_String::as_utf8_string(string);
1428 return ret;
1429 }
1430
|