Path: blob/master/src/hotspot/share/ci/ciConstantPoolCache.cpp
40931 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.inline.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<int>(arena, expected_size, 0, 0);41}4243int ciConstantPoolCache::key_compare(const int& key, const int& elt) {44if (key < elt) return -1;45else if (key > elt) return 1;46else return 0;47}4849// ------------------------------------------------------------------50// ciConstantPoolCache::get51//52// Get the entry at some index53void* ciConstantPoolCache::get(int index) {54ASSERT_IN_VM;55bool found = false;56int pos = _keys->find_sorted<int, ciConstantPoolCache::key_compare>(index, found);57if (!found) {58// This element is not present in the cache.59return NULL;60}61return _elements->at(pos);62}6364// ------------------------------------------------------------------65// ciConstantPoolCache::insert66//67// Insert a ciObject into the table at some index.68void ciConstantPoolCache::insert(int index, void* elem) {69bool found = false;70int pos = _keys->find_sorted<int, ciConstantPoolCache::key_compare>(index, found);71assert(!found, "duplicate");72_keys->insert_before(pos, index);73_elements->insert_before(pos, elem);74}7576// ------------------------------------------------------------------77// ciConstantPoolCache::print78//79// Print debugging information about the cache.80void ciConstantPoolCache::print() {81Unimplemented();82}838485