Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/ci/ciConstantPoolCache.cpp
32285 views
/*1* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "ci/ciConstantPoolCache.hpp"26#include "ci/ciUtilities.hpp"27#include "memory/allocation.hpp"28#include "memory/allocation.inline.hpp"2930// ciConstantPoolCache31//32// This class caches indexed constant pool lookups.3334// ------------------------------------------------------------------35// ciConstantPoolCache::ciConstantPoolCache36ciConstantPoolCache::ciConstantPoolCache(Arena* arena,37int expected_size) {38_elements =39new (arena) GrowableArray<void*>(arena, expected_size, 0, 0);40_keys = new (arena) GrowableArray<intptr_t>(arena, expected_size, 0, 0);41}4243// ------------------------------------------------------------------44// ciConstantPoolCache::get45//46// Get the entry at some index47void* ciConstantPoolCache::get(int index) {48ASSERT_IN_VM;49int pos = find(index);50if (pos >= _keys->length() ||51_keys->at(pos) != index) {52// This element is not present in the cache.53return NULL;54}55return _elements->at(pos);56}5758// ------------------------------------------------------------------59// ciConstantPoolCache::find60//61// Use binary search to find the position of this index in the cache.62// If there is no entry in the cache corresponding to this oop, return63// the position at which the index would be inserted.64int ciConstantPoolCache::find(int key) {65int min = 0;66int max = _keys->length()-1;6768while (max >= min) {69int mid = (max + min) / 2;70int value = _keys->at(mid);71if (value < key) {72min = mid + 1;73} else if (value > key) {74max = mid - 1;75} else {76return mid;77}78}79return min;80}8182// ------------------------------------------------------------------83// ciConstantPoolCache::insert84//85// Insert a ciObject into the table at some index.86void ciConstantPoolCache::insert(int index, void* elem) {87int i;88int pos = find(index);89for (i = _keys->length()-1; i >= pos; i--) {90_keys->at_put_grow(i+1, _keys->at(i));91_elements->at_put_grow(i+1, _elements->at(i));92}93_keys->at_put_grow(pos, index);94_elements->at_put_grow(pos, elem);95}9697// ------------------------------------------------------------------98// ciConstantPoolCache::print99//100// Print debugging information about the cache.101void ciConstantPoolCache::print() {102Unimplemented();103}104105106