Fix LDC, LDC_W, and INSTANCEOF opcodes, more debugging
[jamvm-avr32-jem.git] / src / hash.c
blobf32c7706954633471484edefe2bc8e12c86abaa2
1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2007
3 * Robert Lougher <rob@lougher.org.uk>.
5 * This file is part of JamVM.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <string.h>
23 #include <stdlib.h>
24 #include "jam.h"
25 #include "hash.h"
27 void lockHashTable0(HashTable *table, Thread *self) {
28 if(!tryLockVMLock(table->lock, self)) {
29 disableSuspend(self);
30 lockVMLock(table->lock, self);
31 enableSuspend(self);
33 fastDisableSuspend(self);
36 void unlockHashTable0(HashTable *table, Thread *self) {
37 fastEnableSuspend(self);
38 unlockVMLock(table->lock, self);
41 void resizeHash(HashTable *table, int new_size) {
42 HashEntry *new_table = (HashEntry*)gcMemMalloc(sizeof(HashEntry)*new_size);
43 int i;
45 memset(new_table, 0, sizeof(HashEntry)*new_size);
47 for(i = table->hash_size-1; i >= 0; i--) {
48 void *ptr = table->hash_table[i].data;
49 if(ptr != NULL) {
50 int hash = table->hash_table[i].hash;
51 int new_index = hash & (new_size - 1);
53 while(new_table[new_index].data != NULL)
54 new_index = (new_index+1) & (new_size - 1);
56 new_table[new_index].hash = hash;
57 new_table[new_index].data = ptr;
61 gcMemFree(table->hash_table);
62 table->hash_table = new_table;
63 table->hash_size = new_size;