1 /* src/toolbox/hashtable.c - functions for internal hashtables
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 #include "mm/memory.h"
31 #include "threads/lock-common.h"
33 #include "toolbox/hashtable.h"
35 #include "vm/global.h"
38 /* hashtable_create ************************************************************
40 Initializes a hashtable structure and allocates memory. The
41 parameter size specifies the initial size of the hashtable.
43 *******************************************************************************/
45 void hashtable_create(hashtable *hash, u4 size)
47 /* initialize locking pointer */
49 #if defined(ENABLE_THREADS)
50 /* We need to seperately allocate a java_object_t here, as we
51 need to store the lock object in the new hashtable if it's
52 resized. Otherwise we get an IllegalMonitorStateException. */
54 hash->header = NEW(java_object_t);
56 LOCK_INIT_OBJECT_LOCK(hash->header);
59 /* set initial hash values */
63 hash->ptr = MNEW(void*, size);
65 /* MNEW always allocates memory zeroed out, no need to clear the table */
69 /* hashtable_resize ************************************************************
71 Creates a new hashtable with specified size and moves the important
72 stuff from the old hashtable.
74 *******************************************************************************/
76 hashtable *hashtable_resize(hashtable *hash, u4 size)
80 /* create new hashtable with specified size */
82 newhash = NEW(hashtable);
84 hashtable_create(newhash, size);
86 #if defined(ENABLE_THREADS)
87 /* We need to store the old lock object in the new hashtable.
88 Otherwise we get an IllegalMonitorStateException. */
90 FREE(newhash->header, java_object_t);
92 newhash->header = hash->header;
95 /* store the number of entries in the new hashtable */
97 newhash->entries = hash->entries;
103 /* hashtable_free **************************************************************
105 Simply frees the hashtable.
107 ATTENTION: It does NOT free the lock object!
109 *******************************************************************************/
111 void hashtable_free(hashtable *hash)
113 MFREE(hash->ptr, void*, hash->size);
114 FREE(hash, hashtable);
119 * These are local overrides for various environment variables in Emacs.
120 * Please do not remove this and leave it at the end of the file, where
121 * Emacs will automagically detect them.
122 * ---------------------------------------------------------------------
125 * indent-tabs-mode: t