1 /* src/toolbox/hashtable.c - functions for internal hashtables
3 Copyright (C) 1996-2005, 2006, 2007 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 $Id: hashtable.c 7813 2007-04-25 19:20:13Z twisti $
33 #include "mm/memory.h"
35 #include "threads/lock-common.h"
37 #include "toolbox/hashtable.h"
39 #include "vm/global.h"
42 /* hashtable_create ************************************************************
44 Initializes a hashtable structure and allocates memory. The
45 parameter size specifies the initial size of the hashtable.
47 *******************************************************************************/
49 void hashtable_create(hashtable *hash, u4 size)
51 /* initialize locking pointer */
53 #if defined(ENABLE_THREADS)
54 /* We need to seperately allocate a java_objectheader here, as we
55 need to store the lock object in the new hashtable if it's
56 resized. Otherwise we get an IllegalMonitorStateException. */
58 hash->header = NEW(java_objectheader);
60 LOCK_INIT_OBJECT_LOCK(hash->header);
63 /* set initial hash values */
67 hash->ptr = MNEW(void*, size);
69 /* MNEW always allocates memory zeroed out, no need to clear the table */
73 /* hashtable_resize ************************************************************
75 Creates a new hashtable with specified size and moves the important
76 stuff from the old hashtable.
78 *******************************************************************************/
80 hashtable *hashtable_resize(hashtable *hash, u4 size)
84 /* create new hashtable with specified size */
86 newhash = NEW(hashtable);
88 hashtable_create(newhash, size);
90 #if defined(ENABLE_THREADS)
91 /* We need to store the old lock object in the new hashtable.
92 Otherwise we get an IllegalMonitorStateException. */
94 FREE(newhash->header, java_objectheader);
96 newhash->header = hash->header;
99 /* store the number of entries in the new hashtable */
101 newhash->entries = hash->entries;
107 /* hashtable_free **************************************************************
109 Simply frees the hashtable.
111 ATTENTION: It does NOT free the lock object!
113 *******************************************************************************/
115 void hashtable_free(hashtable *hash)
117 MFREE(hash->ptr, void*, hash->size);
118 FREE(hash, hashtable);
123 * These are local overrides for various environment variables in Emacs.
124 * Please do not remove this and leave it at the end of the file, where
125 * Emacs will automagically detect them.
126 * ---------------------------------------------------------------------
129 * indent-tabs-mode: t