3149N/A * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 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 0N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Oracle in the LICENSE file that accompanied this code. 0N/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 * 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, 1472N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2772N/A * Each object sent to the front end is tracked with the RefNode struct 1879N/A * External to this module, objects are identified by a jlong id which is 1879N/A * simply the sequence number. A weak reference is usually used so that 1879N/A * the presence of a debugger-tracked object will not prevent 1879N/A * its collection. Once an object is collected, its RefNode may be 1879N/A * deleted and the weak ref inside may be reused (these may happen in 1879N/A * either order). Using the sequence number 1879N/A * as the object id prevents ambiguity in the object id when the weak ref 1879N/A * is reused. The RefNode* is stored with the object as it's JVMTI Tag. 1879N/A * The ref member is changed from weak to strong when 1879N/A * gc of the object is to be prevented. 1879N/A * Whether or not it is strong, it is never exported from this module. 1879N/A * A reference count of each jobject is also maintained here. It tracks 1879N/A * the number times an object has been referenced through 1879N/A * commonRef_refToID. A RefNode is freed once the reference 1879N/A * count is decremented to 0 (with commonRef_release*), even if the 1879N/A * correspoding object has not been collected. 3695N/A * One hash table is maintained. The mapping of ID to jobject (or RefNode*) 1879N/A * is handled with one hash table that will re-size itself as the number 1879N/A/* Initial hash table size (must be power of 2) */ 1879N/A/* If element count exceeds HASH_EXPAND_SCALE*hash_size we expand & re-hash */ 1879N/A/* Maximum hash table size (must be power of 2) */ 1879N/A/* Map a key (ID) to a hash bucket */ 1879N/A /* Size should always be a power of 2, use mask instead of mod operator */ 1879N/A/* Create a fresh RefNode structure, create a weak ref and tag the object */ 1879N/A /* Could allocate RefNode's in blocks, not sure it would help much */ 1879N/A /* Create weak reference to make sure we have a reference */ 1879N/A /* Count RefNode's created */ 1879N/A/* Change a RefNode to have a strong reference */ 1879N/A * NewGlobalRef on a weak ref will return NULL if the weak 1879N/A * reference has been collected or if out of memory. 1879N/A * We need to distinguish those two occurrences. 1879N/A/* Change a RefNode to have a weak reference */ 2772N/A * Returns the node which contains the common reference for the 2772N/A * given object. The passed reference should not be a weak reference 2772N/A * managed in the object hash table (i.e. returned by commonRef_idToRef) 2772N/A * because no sequence number checking is done. 1879N/A/* Locate and delete a node based on ID */ 0N/A /* Detach from id hash table */ 3863N/A * Returns the node stored in the object hash table for the given object 3863N/A * id. The id should be a value previously returned by 0N/A * NOTE: It is possible that a match is found here, but that the object 0N/A * is garbage collected by the time the caller inspects node->ref. 0N/A * Callers should take care using the node->ref object returned here. 0N/A /* Re-order hash list so this one is up front */ 0N/A/* Initialize the hash table stored in gdata area */ 0N/A /* Size should always be a power of 2 */ 0N/A/* hash in a RefNode */ 0N/A /* Add to id hashtable */ 0N/A/* Allocate and add RefNode to hash table */ 0N/A /* Allocate the node and set it up */ 3186N/A /* See if hash table needs expansion */ 0N/A /* Save old information */ 0N/A /* Allocate new hash table */ 2772N/A /* Walk over old one and hash in all the RefNodes */ 0N/A /* Add to id hashtable */ 2772N/A/* Initialize the commonRefs usage */ 2772N/A/* Reset the commonRefs usage */ 0N/A /* Toss entire hash table and re-create a new one */ 2062N/A * Given a reference obtained from JNI or JVMTI, return an object 2062N/A * id suitable for sending to the debugger front end. 0N/A * Given an object ID obtained from the debugger front end, return a 0N/A * strong, global reference to that object (or NULL if the object 0N/A * has been collected). The reference can then be used for JNI and 0N/A * JVMTI calls. Caller is resposible for deleting the returned reference. 0N/A /* Object was GC'd shortly after we found the node */ 2772N/A/* Deletes the global reference that commonRef_idToRef() created */ 0N/A/* Prevent garbage collection of an object */ 0N/A * Referent has been collected, clean up now. 0N/A/* Permit garbage collection of an object */ 0N/A/* Release tracking of an object by ID */ 0N/A/* Get rid of RefNodes for objects that no longer exist */ 0N/A * Walk through the id-based hash table. Detach any nodes 0N/A * for which the ref has been collected. 0N/A /* Has the object been collected? */ 0N/A /* Detach from the ID list */ 0N/A/* Lock the commonRef tables */ 0N/A/* Unlock the commonRef tables */