Tue, 15 May 2012 10:10:23 +0200
7133857: exp() and pow() should use the x87 ISA on x86
Summary: use x87 instructions to implement exp() and pow() in interpreter/c1/c2.
Reviewed-by: kvn, never, twisti
duke@435 | 1 | /* |
stefank@2314 | 2 | * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "interpreter/bytecodeHistogram.hpp" |
stefank@2314 | 27 | #include "memory/resourceArea.hpp" |
stefank@2314 | 28 | #include "runtime/os.hpp" |
stefank@2314 | 29 | #include "utilities/growableArray.hpp" |
duke@435 | 30 | |
duke@435 | 31 | // ------------------------------------------------------------------------------------------------ |
duke@435 | 32 | // Non-product code |
duke@435 | 33 | #ifndef PRODUCT |
duke@435 | 34 | |
duke@435 | 35 | // Implementation of BytecodeCounter |
duke@435 | 36 | |
duke@435 | 37 | int BytecodeCounter::_counter_value = 0; |
duke@435 | 38 | jlong BytecodeCounter::_reset_time = 0; |
duke@435 | 39 | |
duke@435 | 40 | |
duke@435 | 41 | void BytecodeCounter::reset() { |
duke@435 | 42 | _counter_value = 0; |
duke@435 | 43 | _reset_time = os::elapsed_counter(); |
duke@435 | 44 | } |
duke@435 | 45 | |
duke@435 | 46 | |
duke@435 | 47 | double BytecodeCounter::elapsed_time() { |
duke@435 | 48 | return (double)(os::elapsed_counter() - _reset_time) / (double)os::elapsed_frequency(); |
duke@435 | 49 | } |
duke@435 | 50 | |
duke@435 | 51 | |
duke@435 | 52 | double BytecodeCounter::frequency() { |
duke@435 | 53 | return (double)counter_value() / elapsed_time(); |
duke@435 | 54 | } |
duke@435 | 55 | |
duke@435 | 56 | |
duke@435 | 57 | void BytecodeCounter::print() { |
duke@435 | 58 | tty->print_cr( |
duke@435 | 59 | "%d bytecodes executed in %.1fs (%.3fMHz)", |
duke@435 | 60 | counter_value(), |
duke@435 | 61 | elapsed_time(), |
duke@435 | 62 | frequency() / 1000000.0 |
duke@435 | 63 | ); |
duke@435 | 64 | } |
duke@435 | 65 | |
duke@435 | 66 | |
duke@435 | 67 | // Helper class for sorting |
duke@435 | 68 | |
duke@435 | 69 | class HistoEntry: public ResourceObj { |
duke@435 | 70 | private: |
duke@435 | 71 | int _index; |
duke@435 | 72 | int _count; |
duke@435 | 73 | |
duke@435 | 74 | public: |
duke@435 | 75 | HistoEntry(int index, int count) { _index = index; _count = count; } |
duke@435 | 76 | int index() const { return _index; } |
duke@435 | 77 | int count() const { return _count; } |
duke@435 | 78 | |
duke@435 | 79 | static int compare(HistoEntry** x, HistoEntry** y) { return (*x)->count() - (*y)->count(); } |
duke@435 | 80 | }; |
duke@435 | 81 | |
duke@435 | 82 | |
duke@435 | 83 | // Helper functions |
duke@435 | 84 | |
duke@435 | 85 | static GrowableArray<HistoEntry*>* sorted_array(int* array, int length) { |
duke@435 | 86 | GrowableArray<HistoEntry*>* a = new GrowableArray<HistoEntry*>(length); |
duke@435 | 87 | int i = length; |
duke@435 | 88 | while (i-- > 0) a->append(new HistoEntry(i, array[i])); |
duke@435 | 89 | a->sort(HistoEntry::compare); |
duke@435 | 90 | return a; |
duke@435 | 91 | } |
duke@435 | 92 | |
duke@435 | 93 | |
duke@435 | 94 | static int total_count(GrowableArray<HistoEntry*>* profile) { |
duke@435 | 95 | int sum = 0; |
duke@435 | 96 | int i = profile->length(); |
duke@435 | 97 | while (i-- > 0) sum += profile->at(i)->count(); |
duke@435 | 98 | return sum; |
duke@435 | 99 | } |
duke@435 | 100 | |
duke@435 | 101 | |
duke@435 | 102 | static const char* name_for(int i) { |
duke@435 | 103 | return Bytecodes::is_defined(i) ? Bytecodes::name(Bytecodes::cast(i)) : "xxxunusedxxx"; |
duke@435 | 104 | } |
duke@435 | 105 | |
duke@435 | 106 | |
duke@435 | 107 | // Implementation of BytecodeHistogram |
duke@435 | 108 | |
duke@435 | 109 | int BytecodeHistogram::_counters[Bytecodes::number_of_codes]; |
duke@435 | 110 | |
duke@435 | 111 | |
duke@435 | 112 | void BytecodeHistogram::reset() { |
duke@435 | 113 | int i = Bytecodes::number_of_codes; |
duke@435 | 114 | while (i-- > 0) _counters[i] = 0; |
duke@435 | 115 | } |
duke@435 | 116 | |
duke@435 | 117 | |
duke@435 | 118 | void BytecodeHistogram::print(float cutoff) { |
duke@435 | 119 | ResourceMark rm; |
duke@435 | 120 | GrowableArray<HistoEntry*>* profile = sorted_array(_counters, Bytecodes::number_of_codes); |
duke@435 | 121 | // print profile |
duke@435 | 122 | int tot = total_count(profile); |
duke@435 | 123 | int abs_sum = 0; |
duke@435 | 124 | tty->cr(); //0123456789012345678901234567890123456789012345678901234567890123456789 |
duke@435 | 125 | tty->print_cr("Histogram of %d executed bytecodes:", tot); |
duke@435 | 126 | tty->cr(); |
duke@435 | 127 | tty->print_cr(" absolute relative code name"); |
duke@435 | 128 | tty->print_cr("----------------------------------------------------------------------"); |
duke@435 | 129 | int i = profile->length(); |
duke@435 | 130 | while (i-- > 0) { |
duke@435 | 131 | HistoEntry* e = profile->at(i); |
duke@435 | 132 | int abs = e->count(); |
duke@435 | 133 | float rel = abs * 100.0F / tot; |
duke@435 | 134 | if (cutoff <= rel) { |
duke@435 | 135 | tty->print_cr("%10d %7.2f%% %02x %s", abs, rel, e->index(), name_for(e->index())); |
duke@435 | 136 | abs_sum += abs; |
duke@435 | 137 | } |
duke@435 | 138 | } |
duke@435 | 139 | tty->print_cr("----------------------------------------------------------------------"); |
duke@435 | 140 | float rel_sum = abs_sum * 100.0F / tot; |
duke@435 | 141 | tty->print_cr("%10d %7.2f%% (cutoff = %.2f%%)", abs_sum, rel_sum, cutoff); |
duke@435 | 142 | tty->cr(); |
duke@435 | 143 | } |
duke@435 | 144 | |
duke@435 | 145 | |
duke@435 | 146 | // Implementation of BytecodePairHistogram |
duke@435 | 147 | |
duke@435 | 148 | int BytecodePairHistogram::_index; |
duke@435 | 149 | int BytecodePairHistogram::_counters[BytecodePairHistogram::number_of_pairs]; |
duke@435 | 150 | |
duke@435 | 151 | |
duke@435 | 152 | void BytecodePairHistogram::reset() { |
duke@435 | 153 | _index = Bytecodes::_nop << log2_number_of_codes; |
duke@435 | 154 | |
duke@435 | 155 | int i = number_of_pairs; |
duke@435 | 156 | while (i-- > 0) _counters[i] = 0; |
duke@435 | 157 | } |
duke@435 | 158 | |
duke@435 | 159 | |
duke@435 | 160 | void BytecodePairHistogram::print(float cutoff) { |
duke@435 | 161 | ResourceMark rm; |
duke@435 | 162 | GrowableArray<HistoEntry*>* profile = sorted_array(_counters, number_of_pairs); |
duke@435 | 163 | // print profile |
duke@435 | 164 | int tot = total_count(profile); |
duke@435 | 165 | int abs_sum = 0; |
duke@435 | 166 | tty->cr(); //0123456789012345678901234567890123456789012345678901234567890123456789 |
duke@435 | 167 | tty->print_cr("Histogram of %d executed bytecode pairs:", tot); |
duke@435 | 168 | tty->cr(); |
duke@435 | 169 | tty->print_cr(" absolute relative codes 1st bytecode 2nd bytecode"); |
duke@435 | 170 | tty->print_cr("----------------------------------------------------------------------"); |
duke@435 | 171 | int i = profile->length(); |
duke@435 | 172 | while (i-- > 0) { |
duke@435 | 173 | HistoEntry* e = profile->at(i); |
duke@435 | 174 | int abs = e->count(); |
duke@435 | 175 | float rel = abs * 100.0F / tot; |
duke@435 | 176 | if (cutoff <= rel) { |
duke@435 | 177 | int c1 = e->index() % number_of_codes; |
duke@435 | 178 | int c2 = e->index() / number_of_codes; |
duke@435 | 179 | tty->print_cr("%10d %6.3f%% %02x %02x %-19s %s", abs, rel, c1, c2, name_for(c1), name_for(c2)); |
duke@435 | 180 | abs_sum += abs; |
duke@435 | 181 | } |
duke@435 | 182 | } |
duke@435 | 183 | tty->print_cr("----------------------------------------------------------------------"); |
duke@435 | 184 | float rel_sum = abs_sum * 100.0F / tot; |
duke@435 | 185 | tty->print_cr("%10d %6.3f%% (cutoff = %.3f%%)", abs_sum, rel_sum, cutoff); |
duke@435 | 186 | tty->cr(); |
duke@435 | 187 | } |
duke@435 | 188 | |
duke@435 | 189 | #endif |