Mon, 26 Apr 2010 23:59:45 -0700
6943485: JVMTI always on capabilities change code generation too much
Reviewed-by: twisti, dcubed
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 1999 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 | #include "incls/_precompiled.incl" |
duke@435 | 26 | #include "incls/_ciConstantPoolCache.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | // ciConstantPoolCache |
duke@435 | 29 | // |
duke@435 | 30 | // This class caches indexed constant pool lookups. |
duke@435 | 31 | |
duke@435 | 32 | // ------------------------------------------------------------------ |
duke@435 | 33 | // ciConstantPoolCache::ciConstantPoolCache |
duke@435 | 34 | ciConstantPoolCache::ciConstantPoolCache(Arena* arena, |
duke@435 | 35 | int expected_size) { |
duke@435 | 36 | _elements = |
duke@435 | 37 | new (arena) GrowableArray<void*>(arena, expected_size, 0, 0); |
duke@435 | 38 | _keys = new (arena) GrowableArray<intptr_t>(arena, expected_size, 0, 0); |
duke@435 | 39 | } |
duke@435 | 40 | |
duke@435 | 41 | // ------------------------------------------------------------------ |
duke@435 | 42 | // ciConstantPoolCache::get |
duke@435 | 43 | // |
duke@435 | 44 | // Get the entry at some index |
duke@435 | 45 | void* ciConstantPoolCache::get(int index) { |
duke@435 | 46 | ASSERT_IN_VM; |
duke@435 | 47 | int pos = find(index); |
duke@435 | 48 | if (pos >= _keys->length() || |
duke@435 | 49 | _keys->at(pos) != index) { |
duke@435 | 50 | // This element is not present in the cache. |
duke@435 | 51 | return NULL; |
duke@435 | 52 | } |
duke@435 | 53 | return _elements->at(pos); |
duke@435 | 54 | } |
duke@435 | 55 | |
duke@435 | 56 | // ------------------------------------------------------------------ |
duke@435 | 57 | // ciConstantPoolCache::find |
duke@435 | 58 | // |
duke@435 | 59 | // Use binary search to find the position of this index in the cache. |
duke@435 | 60 | // If there is no entry in the cache corresponding to this oop, return |
duke@435 | 61 | // the position at which the index would be inserted. |
duke@435 | 62 | int ciConstantPoolCache::find(int key) { |
duke@435 | 63 | int min = 0; |
duke@435 | 64 | int max = _keys->length()-1; |
duke@435 | 65 | |
duke@435 | 66 | while (max >= min) { |
duke@435 | 67 | int mid = (max + min) / 2; |
duke@435 | 68 | int value = _keys->at(mid); |
duke@435 | 69 | if (value < key) { |
duke@435 | 70 | min = mid + 1; |
duke@435 | 71 | } else if (value > key) { |
duke@435 | 72 | max = mid - 1; |
duke@435 | 73 | } else { |
duke@435 | 74 | return mid; |
duke@435 | 75 | } |
duke@435 | 76 | } |
duke@435 | 77 | return min; |
duke@435 | 78 | } |
duke@435 | 79 | |
duke@435 | 80 | // ------------------------------------------------------------------ |
duke@435 | 81 | // ciConstantPoolCache::insert |
duke@435 | 82 | // |
duke@435 | 83 | // Insert a ciObject into the table at some index. |
duke@435 | 84 | void ciConstantPoolCache::insert(int index, void* elem) { |
duke@435 | 85 | int i; |
duke@435 | 86 | int pos = find(index); |
duke@435 | 87 | for (i = _keys->length()-1; i >= pos; i--) { |
duke@435 | 88 | _keys->at_put_grow(i+1, _keys->at(i)); |
duke@435 | 89 | _elements->at_put_grow(i+1, _elements->at(i)); |
duke@435 | 90 | } |
duke@435 | 91 | _keys->at_put_grow(pos, index); |
duke@435 | 92 | _elements->at_put_grow(pos, elem); |
duke@435 | 93 | } |
duke@435 | 94 | |
duke@435 | 95 | // ------------------------------------------------------------------ |
duke@435 | 96 | // ciConstantPoolCache::print |
duke@435 | 97 | // |
duke@435 | 98 | // Print debugging information about the cache. |
duke@435 | 99 | void ciConstantPoolCache::print() { |
duke@435 | 100 | Unimplemented(); |
duke@435 | 101 | } |