1 /*
2 * Copyright (c) 2003, 2011, 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 *
497
498 static int
499 name_for_methodOop(jvm_agent_t* J, uint64_t methodOopPtr, char * result, size_t size)
500 {
501 short nameIndex;
502 short signatureIndex;
503 uint64_t constantPool;
504 uint64_t constMethod;
505 uint64_t nameSymbol;
506 uint64_t signatureSymbol;
507 uint64_t klassPtr;
508 uint64_t klassSymbol;
509 short klassSymbolLength;
510 short nameSymbolLength;
511 short signatureSymbolLength;
512 char * nameString = NULL;
513 char * klassString = NULL;
514 char * signatureString = NULL;
515 int err;
516
517 err = read_pointer(J, methodOopPtr + OFFSET_methodOopDesc_constants, &constantPool);
518 CHECK_FAIL(err);
519 err = read_pointer(J, methodOopPtr + OFFSET_methodOopDesc_constMethod, &constMethod);
520 CHECK_FAIL(err);
521
522 /* To get name string */
523 err = ps_pread(J->P, constMethod + OFFSET_constMethodOopDesc_name_index, &nameIndex, 2);
524 CHECK_FAIL(err);
525 err = read_pointer(J, constantPool + nameIndex * POINTER_SIZE + SIZE_constantPoolOopDesc, &nameSymbol);
526 CHECK_FAIL(err);
527 // The symbol is a CPSlot and has lower bit set to indicate metadata
528 nameSymbol &= (~1); // remove metadata lsb
529 err = ps_pread(J->P, nameSymbol + OFFSET_Symbol_length, &nameSymbolLength, 2);
530 CHECK_FAIL(err);
531 nameString = (char*)calloc(nameSymbolLength + 1, 1);
532 err = ps_pread(J->P, nameSymbol + OFFSET_Symbol_body, nameString, nameSymbolLength);
533 CHECK_FAIL(err);
534
535 /* To get signature string */
536 err = ps_pread(J->P, constMethod + OFFSET_constMethodOopDesc_signature_index, &signatureIndex, 2);
537 CHECK_FAIL(err);
538 err = read_pointer(J, constantPool + signatureIndex * POINTER_SIZE + SIZE_constantPoolOopDesc, &signatureSymbol);
539 CHECK_FAIL(err);
540 signatureSymbol &= (~1); // remove metadata lsb
|
1 /*
2 * Copyright (c) 2003, 2012, 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 *
497
498 static int
499 name_for_methodOop(jvm_agent_t* J, uint64_t methodOopPtr, char * result, size_t size)
500 {
501 short nameIndex;
502 short signatureIndex;
503 uint64_t constantPool;
504 uint64_t constMethod;
505 uint64_t nameSymbol;
506 uint64_t signatureSymbol;
507 uint64_t klassPtr;
508 uint64_t klassSymbol;
509 short klassSymbolLength;
510 short nameSymbolLength;
511 short signatureSymbolLength;
512 char * nameString = NULL;
513 char * klassString = NULL;
514 char * signatureString = NULL;
515 int err;
516
517 err = read_pointer(J, methodOopPtr + OFFSET_methodOopDesc_constMethod, &constMethod);
518 CHECK_FAIL(err);
519 err = read_pointer(J->P, constMethod + OFFSET_constMethodOopDesc_constants, &constantPool);
520 CHECK_FAIL(err);
521
522 /* To get name string */
523 err = ps_pread(J->P, constMethod + OFFSET_constMethodOopDesc_name_index, &nameIndex, 2);
524 CHECK_FAIL(err);
525 err = read_pointer(J, constantPool + nameIndex * POINTER_SIZE + SIZE_constantPoolOopDesc, &nameSymbol);
526 CHECK_FAIL(err);
527 // The symbol is a CPSlot and has lower bit set to indicate metadata
528 nameSymbol &= (~1); // remove metadata lsb
529 err = ps_pread(J->P, nameSymbol + OFFSET_Symbol_length, &nameSymbolLength, 2);
530 CHECK_FAIL(err);
531 nameString = (char*)calloc(nameSymbolLength + 1, 1);
532 err = ps_pread(J->P, nameSymbol + OFFSET_Symbol_body, nameString, nameSymbolLength);
533 CHECK_FAIL(err);
534
535 /* To get signature string */
536 err = ps_pread(J->P, constMethod + OFFSET_constMethodOopDesc_signature_index, &signatureIndex, 2);
537 CHECK_FAIL(err);
538 err = read_pointer(J, constantPool + signatureIndex * POINTER_SIZE + SIZE_constantPoolOopDesc, &signatureSymbol);
539 CHECK_FAIL(err);
540 signatureSymbol &= (~1); // remove metadata lsb
|