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
31 #include "mm/memory.h"
33 #include "threads/lock-common.h"
35 #include "toolbox/hashtable.h"
37 #include "vm/global.h"
40 /* hashtable_create ************************************************************
42 Initializes a hashtable structure and allocates memory. The
43 parameter size specifies the initial size of the hashtable.
45 *******************************************************************************/
47 void hashtable_create(hashtable *hash, u4 size)
49 /* initialize locking pointer */
51 #if defined(ENABLE_THREADS)
52 /* We need to seperately allocate a java_object_t here, as we
53 need to store the lock object in the new hashtable if it's
54 resized. Otherwise we get an IllegalMonitorStateException. */
56 hash->header = NEW(java_object_t);
58 LOCK_INIT_OBJECT_LOCK(hash->header);
61 /* set initial hash values */
65 hash->ptr = MNEW(void*, size);
67 /* MNEW always allocates memory zeroed out, no need to clear the table */
71 /* hashtable_resize ************************************************************
73 Creates a new hashtable with specified size and moves the important
74 stuff from the old hashtable.
76 *******************************************************************************/
78 hashtable *hashtable_resize(hashtable *hash, u4 size)
82 /* create new hashtable with specified size */
84 newhash = NEW(hashtable);
86 hashtable_create(newhash, size);
88 #if defined(ENABLE_THREADS)
89 /* We need to store the old lock object in the new hashtable.
90 Otherwise we get an IllegalMonitorStateException. */
92 FREE(newhash->header, java_object_t);
94 newhash->header = hash->header;
97 /* store the number of entries in the new hashtable */
99 newhash->entries = hash->entries;
105 /* hashtable_free **************************************************************
107 Simply frees the hashtable.
109 ATTENTION: It does NOT free the lock object!
111 *******************************************************************************/
113 void hashtable_free(hashtable *hash)
115 MFREE(hash->ptr, void*, hash->size);
116 FREE(hash, hashtable);
121 * These are local overrides for various environment variables in Emacs.
122 * Please do not remove this and leave it at the end of the file, where
123 * Emacs will automagically detect them.
124 * ---------------------------------------------------------------------
127 * indent-tabs-mode: t