001/* 002 * This file is part of the Jikes RVM project (http://jikesrvm.org). 003 * 004 * This file is licensed to You under the Eclipse Public License (EPL); 005 * You may not use this file except in compliance with the License. You 006 * may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/eclipse-1.0.php 009 * 010 * See the COPYRIGHT.txt file distributed with this work for information 011 * regarding copyright ownership. 012 */ 013package org.jikesrvm.util; 014 015import org.jikesrvm.util.ImmutableEntryHashMapRVM.Bucket; 016import org.jikesrvm.runtime.Magic; 017 018/** 019 * A hash map with entirely immutable buckets. It doesn't correctly support 020 * remove, and its values cannot be mutated by a put with the same key. 021 */ 022public final class ImmutableEntryIdentityHashMapRVM<K, V> extends AbstractHashMapRVM<K,V> { 023 024 @Override 025 AbstractBucket<K,V> createNewBucket(K key, V value, AbstractBucket<K, V> next) { 026 return new Bucket<K,V>(key, value, next); 027 } 028 029 public ImmutableEntryIdentityHashMapRVM() { 030 super(DEFAULT_SIZE); 031 } 032 033 public ImmutableEntryIdentityHashMapRVM(int size) { 034 super(size); 035 } 036 037 @Override 038 public V remove(K key) { 039 throw new UnsupportedOperationException(); 040 } 041 042 @Override 043 public void removeAll() { 044 throw new UnsupportedOperationException(); 045 } 046 047 @Override 048 protected boolean same(K k1, K k2) { 049 return k1 == k2; 050 } 051 052 @Override 053 protected int hashTheKey(K key) { 054 if (!org.jikesrvm.VM.runningVM) { 055 return Magic.bootImageIdentityHashCode(key); 056 } else { 057 return System.identityHashCode(key); 058 } 059 } 060}