Fri, 10 Jul 2009 11:10:00 -0700
6857194: Add hotspot perf counters to aid class loading performance measurement
Summary: Add new jvmstat counters to measure detailed class loading time
Reviewed-by: acorn, kamg
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | class BciMap; |
duke@435 | 26 | |
duke@435 | 27 | // methodComparator provides an interface for determining if methods of |
duke@435 | 28 | // different versions of classes are equivalent or switchable |
duke@435 | 29 | |
duke@435 | 30 | class MethodComparator { |
duke@435 | 31 | private: |
duke@435 | 32 | static BytecodeStream *_s_old, *_s_new; |
duke@435 | 33 | static constantPoolOop _old_cp, _new_cp; |
duke@435 | 34 | static BciMap *_bci_map; |
duke@435 | 35 | static bool _switchable_test; |
duke@435 | 36 | static GrowableArray<int> *_fwd_jmps; |
duke@435 | 37 | |
duke@435 | 38 | static bool args_same(Bytecodes::Code c_old, Bytecodes::Code c_new); |
duke@435 | 39 | static int check_stack_and_locals_size(methodOop old_method, methodOop new_method); |
duke@435 | 40 | |
duke@435 | 41 | public: |
duke@435 | 42 | // Check if the new method is equivalent to the old one modulo constant pool (EMCP). |
duke@435 | 43 | // Intuitive definition: two versions of the same method are EMCP, if they don't differ |
duke@435 | 44 | // on the source code level. Practically, we check whether the only difference between |
duke@435 | 45 | // method versions is some constantpool indices embedded into the bytecodes, and whether |
duke@435 | 46 | // these indices eventually point to the same constants for both method versions. |
duke@435 | 47 | static bool methods_EMCP(methodOop old_method, methodOop new_method); |
duke@435 | 48 | |
duke@435 | 49 | static bool methods_switchable(methodOop old_method, methodOop new_method, BciMap &bci_map); |
duke@435 | 50 | }; |
duke@435 | 51 | |
duke@435 | 52 | |
duke@435 | 53 | // ByteCode Index Map. For two versions of the same method, where the new version may contain |
duke@435 | 54 | // fragments not found in the old version, provides a mapping from an index of a bytecode in |
duke@435 | 55 | // the old method to the index of the same bytecode in the new method. |
duke@435 | 56 | |
duke@435 | 57 | class BciMap { |
duke@435 | 58 | private: |
duke@435 | 59 | int *_old_bci, *_new_st_bci, *_new_end_bci; |
duke@435 | 60 | int _cur_size, _cur_pos; |
duke@435 | 61 | int _pos; |
duke@435 | 62 | |
duke@435 | 63 | public: |
duke@435 | 64 | BciMap() { |
duke@435 | 65 | _cur_size = 50; |
duke@435 | 66 | _old_bci = (int*) malloc(sizeof(int) * _cur_size); |
duke@435 | 67 | _new_st_bci = (int*) malloc(sizeof(int) * _cur_size); |
duke@435 | 68 | _new_end_bci = (int*) malloc(sizeof(int) * _cur_size); |
duke@435 | 69 | _cur_pos = 0; |
duke@435 | 70 | } |
duke@435 | 71 | |
duke@435 | 72 | ~BciMap() { |
duke@435 | 73 | free(_old_bci); |
duke@435 | 74 | free(_new_st_bci); |
duke@435 | 75 | free(_new_end_bci); |
duke@435 | 76 | } |
duke@435 | 77 | |
duke@435 | 78 | // Store the position of an added fragment, e.g. |
duke@435 | 79 | // |
duke@435 | 80 | // |<- old_bci |
duke@435 | 81 | // ----------------------------------------- |
duke@435 | 82 | // Old method |invokevirtual 5|aload 1|... |
duke@435 | 83 | // ----------------------------------------- |
duke@435 | 84 | // |
duke@435 | 85 | // |<- new_st_bci |<- new_end_bci |
duke@435 | 86 | // -------------------------------------------------------------------- |
duke@435 | 87 | // New method |invokevirual 5|aload 2|invokevirtual 6|aload 1|... |
duke@435 | 88 | // -------------------------------------------------------------------- |
duke@435 | 89 | // ^^^^^^^^^^^^^^^^^^^^^^^^ |
duke@435 | 90 | // Added fragment |
duke@435 | 91 | |
duke@435 | 92 | void store_fragment_location(int old_bci, int new_st_bci, int new_end_bci) { |
duke@435 | 93 | if (_cur_pos == _cur_size) { |
duke@435 | 94 | _cur_size += 10; |
duke@435 | 95 | _old_bci = (int*) realloc(_old_bci, sizeof(int) * _cur_size); |
duke@435 | 96 | _new_st_bci = (int*) realloc(_new_st_bci, sizeof(int) * _cur_size); |
duke@435 | 97 | _new_end_bci = (int*) realloc(_new_end_bci, sizeof(int) * _cur_size); |
duke@435 | 98 | } |
duke@435 | 99 | _old_bci[_cur_pos] = old_bci; |
duke@435 | 100 | _new_st_bci[_cur_pos] = new_st_bci; |
duke@435 | 101 | _new_end_bci[_cur_pos] = new_end_bci; |
duke@435 | 102 | _cur_pos++; |
duke@435 | 103 | } |
duke@435 | 104 | |
duke@435 | 105 | int new_bci_for_old(int old_bci) { |
duke@435 | 106 | if (_cur_pos == 0 || old_bci < _old_bci[0]) return old_bci; |
duke@435 | 107 | _pos = 1; |
duke@435 | 108 | while (_pos < _cur_pos && old_bci >= _old_bci[_pos]) |
duke@435 | 109 | _pos++; |
duke@435 | 110 | return _new_end_bci[_pos-1] + (old_bci - _old_bci[_pos-1]); |
duke@435 | 111 | } |
duke@435 | 112 | |
duke@435 | 113 | // Test if two indexes - one in the old method and another in the new one - correspond |
duke@435 | 114 | // to the same bytecode |
duke@435 | 115 | bool old_and_new_locations_same(int old_dest_bci, int new_dest_bci) { |
duke@435 | 116 | if (new_bci_for_old(old_dest_bci) == new_dest_bci) |
duke@435 | 117 | return true; |
duke@435 | 118 | else if (_old_bci[_pos-1] == old_dest_bci) |
duke@435 | 119 | return (new_dest_bci == _new_st_bci[_pos-1]); |
duke@435 | 120 | else return false; |
duke@435 | 121 | } |
duke@435 | 122 | }; |