1 /* src/vm/hashtable.c - functions for internal hashtables
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Reinhard Grafl
33 $Id: hashtable.c 4921 2006-05-15 14:24:36Z twisti $
41 #include "mm/memory.h"
43 #if defined(ENABLE_THREADS)
44 # include "threads/native/threads.h"
47 #include "vm/hashtable.h"
50 /* hashtable_create ************************************************************
52 Initializes a hashtable structure and allocates memory. The
53 parameter size specifies the initial size of the hashtable.
55 *******************************************************************************/
57 void hashtable_create(hashtable *hash, u4 size)
59 /* initialize locking pointer */
61 #if defined(ENABLE_THREADS)
62 /* We need to seperately allocate a java_objectheader here, as we
63 need to store the lock object in the new hashtable if it's
64 resized. Otherwise we get an IllegalMonitorStateException. */
66 hash->header = NEW(java_objectheader);
68 lock_init_object_lock(hash->header);
71 /* set initial hash values */
75 hash->ptr = MNEW(void*, size);
77 /* MNEW always allocates memory zeroed out, no need to clear the table */
81 /* hashtable_resize ************************************************************
83 Creates a new hashtable with specified size and moves the important
84 stuff from the old hashtable.
86 *******************************************************************************/
88 hashtable *hashtable_resize(hashtable *hash, u4 size)
92 /* create new hashtable with specified size */
94 newhash = NEW(hashtable);
96 hashtable_create(newhash, size);
98 #if defined(ENABLE_THREADS)
99 /* We need to store the old lock object in the new hashtable.
100 Otherwise we get an IllegalMonitorStateException. */
102 FREE(newhash->header, java_objectheader);
104 newhash->header = hash->header;
107 /* store the number of entries in the new hashtable */
109 newhash->entries = hash->entries;
115 /* hashtable_free **************************************************************
117 Simply frees the hashtable.
119 ATTENTION: It does NOT free the lock object!
121 *******************************************************************************/
123 void hashtable_free(hashtable *hash)
125 MFREE(hash->ptr, void*, hash->size);
126 FREE(hash, hashtable);
131 * These are local overrides for various environment variables in Emacs.
132 * Please do not remove this and leave it at the end of the file, where
133 * Emacs will automagically detect them.
134 * ---------------------------------------------------------------------
137 * indent-tabs-mode: t