oopRecorder.hpp revision 0
/*
* Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
// Recording and retrieval of oop relocations in compiled code.
class CodeBlob;
class OopRecorder : public ResourceObj {
public:
// A two-way mapping from positive indexes to oop handles.
// The zero index is reserved for a constant (sharable) null.
// Indexes may not be negative.
// Use the given arena to manage storage, if not NULL.
// By default, uses the current ResourceArea.
// Generate a new index on which CodeBlob::oop_addr_at will work.
// allocate_index and find_index never return the same index,
// and allocate_index never returns the same index twice.
// In fact, two successive calls to allocate_index return successive ints.
int allocate_index(jobject h) {
return add_handle(h, false);
}
// For a given jobject, this will return the same index repeatedly.
// The index can later be given to oop_at to retrieve the oop.
// However, the oop must not be changed via CodeBlob::oop_addr_at.
int find_index(jobject h) {
int index = maybe_find_index(h);
if (index < 0) { // previously unallocated
index = add_handle(h, true);
}
return index;
}
// variant of find_index which does not allocate if not found (yields -1)
int maybe_find_index(jobject h);
// returns the size of the generated oop table, for sizing the CodeBlob.
// must be called after all oops are allocated!
int oop_size();
// Retrieve the oop handle at a given index.
int element_count() {
// there is always a NULL virtually present as first object
}
// copy the generated oop table to CodeBlob
#ifdef ASSERT
bool is_complete() { return _complete; }
#endif
private:
// leaky hash table of handle => index, to help detect duplicate insertion
class IndexCache: public ResourceObj {
// This class is only used by the OopRecorder class.
friend class OopRecorder;
enum {
_log_cache_size = 9,
// Index entries are ints. The LSBit is a collision indicator.
_collision_bit_shift = 0,
_collision_bit = 1,
};
int _cache[_cache_size];
}
}
static bool cache_location_collision(int* cloc) {
return ((*cloc) & _collision_bit) != 0;
}
static int cache_location_index(int* cloc) {
return (*cloc) >> _index_shift;
}
}
IndexCache();
};
// Helper function; returns false for NULL or Universe::non_oop_word().
inline bool is_real_jobject(jobject h);
void maybe_initialize();
bool _complete;
#ifdef ASSERT
#endif
};