0N/A/*
3261N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2362N/A *
2362N/A */
0N/A
0N/A#include "precompiled.hpp"
0N/A#include "ci/ciConstantPoolCache.hpp"
0N/A#include "ci/ciUtilities.hpp"
0N/A#include "memory/allocation.hpp"
0N/A#include "memory/allocation.inline.hpp"
0N/A
0N/A// ciConstantPoolCache
0N/A//
0N/A// This class caches indexed constant pool lookups.
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciConstantPoolCache::ciConstantPoolCache
0N/AciConstantPoolCache::ciConstantPoolCache(Arena* arena,
0N/A int expected_size) {
0N/A _elements =
1999N/A new (arena) GrowableArray<void*>(arena, expected_size, 0, 0);
1999N/A _keys = new (arena) GrowableArray<intptr_t>(arena, expected_size, 0, 0);
0N/A}
0N/A
1999N/A// ------------------------------------------------------------------
0N/A// ciConstantPoolCache::get
1999N/A//
0N/A// Get the entry at some index
0N/Avoid* ciConstantPoolCache::get(int index) {
0N/A ASSERT_IN_VM;
0N/A int pos = find(index);
1999N/A if (pos >= _keys->length() ||
1999N/A _keys->at(pos) != index) {
1999N/A // This element is not present in the cache.
0N/A return NULL;
0N/A }
0N/A return _elements->at(pos);
0N/A}
0N/A
1999N/A// ------------------------------------------------------------------
1999N/A// ciConstantPoolCache::find
1999N/A//
1999N/A// Use binary search to find the position of this index in the cache.
0N/A// If there is no entry in the cache corresponding to this oop, return
0N/A// the position at which the index would be inserted.
0N/Aint ciConstantPoolCache::find(int key) {
0N/A int min = 0;
0N/A int max = _keys->length()-1;
0N/A
0N/A while (max >= min) {
0N/A int mid = (max + min) / 2;
0N/A int value = _keys->at(mid);
0N/A if (value < key) {
1999N/A min = mid + 1;
1999N/A } else if (value > key) {
1999N/A max = mid - 1;
1999N/A } else {
0N/A return mid;
0N/A }
0N/A }
0N/A return min;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciConstantPoolCache::insert
1999N/A//
1999N/A// Insert a ciObject into the table at some index.
1999N/Avoid ciConstantPoolCache::insert(int index, void* elem) {
1999N/A int i;
0N/A int pos = find(index);
0N/A for (i = _keys->length()-1; i >= pos; i--) {
0N/A _keys->at_put_grow(i+1, _keys->at(i));
0N/A _elements->at_put_grow(i+1, _elements->at(i));
0N/A }
0N/A _keys->at_put_grow(pos, index);
0N/A _elements->at_put_grow(pos, elem);
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// ciConstantPoolCache::print
5088N/A//
0N/A// Print debugging information about the cache.
5088N/Avoid ciConstantPoolCache::print() {
0N/A Unimplemented();
0N/A}
0N/A