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 */ 013 package org.jikesrvm.util; 014 015 import org.jikesrvm.util.ImmutableEntryHashMapRVM.Bucket; 016 import 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 */ 022 public 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 protected boolean same(K k1, K k2) { 039 return k1 == k2; 040 } 041 042 @Override 043 protected int hashTheKey(K key) { 044 if (!org.jikesrvm.VM.runningVM) { 045 return Magic.bootImageIdentityHashCode(key); 046 } else { 047 return System.identityHashCode(key); 048 } 049 } 050 }