This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Fix PR java/22189


Robin Green writes:
 > Hi,
 > 
 > Below is a copy of my fix and cleanup for
 > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22189
 > 
 > The actual fix is only one line, but I attempted to rename
 > stuff to clarify the code. Please see the bug report for explanation.
 > 
 > Needs testing and applying.

Seems reasonable, but:

 - Mixes substantive changes and reformatting.

 - Replaces correctly formatted code with differently formatted code
   for no apparent reason; at one point a pair of braces is removed
   and replaced by double-spaced blank lines.

 - A new local variable, realCapacity, is introduced, but it doesn't
   seem to do anything useful.

Can you please submit the substantive change that fixes the bug as a
separate patch?

Thanks,
Andrew.



 > -- 
 > Robin
 > --- /usr/src/debug/gcc-4.0.0-20050622/libjava/gnu/gcj/runtime/PersistentByteMap.java	2005-02-16 17:32:59.000000000 +0000
 > +++ gnu/gcj/runtime/PersistentByteMap.java	2005-06-26 14:46:30.000000000 +0100
 > @@ -58,7 +58,6 @@
 >  import java.nio.*;
 >  import java.nio.channels.*;
 >  import java.util.*;
 > -import java.security.MessageDigest;
 >  import java.math.BigInteger;
 >  
 >  public class PersistentByteMap
 > @@ -67,7 +66,7 @@
 >  
 >    static private final int MAGIC = 0;
 >    static private final int VERSION = 4;
 > -  static private final int CAPACITY = 8;
 > +  static private final int INTERNAL_CAPACITY = 8;
 >    static private final int TABLE_BASE = 12;
 >    static private final int STRING_BASE = 16;
 >    static private final int STRING_SIZE = 20;
 > @@ -78,7 +77,7 @@
 >  
 >    static private final int TABLE_ENTRY_SIZE = 2 * INT_SIZE;
 >  
 > -  private int capacity;   // number of entries
 > +  private int internal_capacity;   // real number of entries
 >    private int table_base;   // offset from start of file, in bytes
 >    private int string_base;  // offset from start of file, in bytes
 >    private int string_size;  // size of string table, in bytes
 > @@ -155,7 +154,7 @@
 >        throw new IllegalArgumentException(f.getName());
 >  
 >      table_base = getWord (TABLE_BASE);
 > -    capacity = getWord (CAPACITY);
 > +    internal_capacity = getWord (INTERNAL_CAPACITY);
 >      string_base = getWord (STRING_BASE);
 >      string_size = getWord (STRING_SIZE);
 >      file_size = getWord (FILE_SIZE);
 > @@ -169,16 +168,15 @@
 >    {
 >      f.createNewFile();
 >      RandomAccessFile raf = new RandomAccessFile(f, "rw");
 > -
 > -    {        
 > +            
 >        // The user has explicitly provided a size for the table.
 >        // We're going to make that size prime.  This isn't
 >        // strictly necessary but it can't hurt.
 >        //
 > -      // We expand the size by 3/2 because the hash table is
 > -      // intolerably slow when more than 2/3 full.
 > +      // We expand the size by 3/2 and round the result because
 > +      // the hash table is intolerably slow when more than 2/3 full.
 >        
 > -      BigInteger size = new BigInteger(Integer.toString(capacity * 3/2));
 > +      BigInteger size = new BigInteger(Integer.toString(((capacity*3)+1)/2));
 >        BigInteger two = BigInteger.ONE.add(BigInteger.ONE);
 >        
 >        if (size.getLowestSetBit() != 0) // A hard way to say isEven()
 > @@ -187,11 +185,11 @@
 >        while (! size.isProbablePrime(10))
 >  	size = size.add(two);
 >        
 > -      this.capacity = capacity = size.intValue();
 > -    }
 > +    int realCapacity = this.internal_capacity = size.intValue();
 > +    
 >  
 >      table_base = 64;
 > -    string_base = table_base + capacity * TABLE_ENTRY_SIZE;
 > +    string_base = table_base + realCapacity * TABLE_ENTRY_SIZE;
 >      string_size = 0;
 >      file_size = string_base;
 >      elements = 0;
 > @@ -207,12 +205,12 @@
 >      fc = raf.getChannel();
 >      buf = fc.map(FileChannel.MapMode.READ_WRITE, 0, raf.length());
 >  
 > -    for (int i = 0; i < capacity; i++)
 > +    for (int i = 0; i < realCapacity; i++)
 >        putKeyPos(UNUSED_ENTRY, i);
 >          
 >      putWord(0x67636a64, MAGIC);
 >      putWord(0x01, VERSION);
 > -    putWord(capacity, CAPACITY);
 > +    putWord(internal_capacity, INTERNAL_CAPACITY);
 >      putWord(table_base, TABLE_BASE);
 >      putWord(string_base, STRING_BASE);
 >      putWord(file_size, FILE_SIZE);
 > @@ -305,7 +303,7 @@
 >           + ((b[1]&0xffL)<<8) 
 >           + ((b[2]&0xffL)<<16) 
 >           + ((b[3]&0xffL)<<24));
 > -    long result = hashIndex % (long)capacity;
 > +    long result = hashIndex % (long)internal_capacity;
 >      return (int)result;
 >    }
 >          
 > @@ -326,7 +324,7 @@
 >          // not be theoretically as good as open addressing, but it has
 >          // good cache behviour.
 >          hashIndex++;
 > -        hashIndex %= capacity;
 > +        hashIndex %= internal_capacity;
 >        }
 >      while (true);
 >    }
 > @@ -360,7 +358,7 @@
 >            }
 >                  
 >          hashIndex++;
 > -        hashIndex %= capacity;
 > +        hashIndex %= internal_capacity;
 >        }
 >      while (true);
 >    }
 > @@ -376,7 +374,7 @@
 >  	  {
 >  	    values = new HashMap();
 >  	
 > -	    for (int i = 0; i < capacity; i++)
 > +	    for (int i = 0; i < internal_capacity; i++)
 >  	      if (getKeyPos(i) != UNUSED_ENTRY)
 >  		{
 >  		  int pos = getValuePos(i);
 > @@ -437,7 +435,7 @@
 >    {
 >      // With the the table 2/3 full there will be on average 2 probes
 >      // for a successful search and 5 probes for an unsuccessful one.
 > -    return capacity * 2/3;
 > +    return internal_capacity * 2/3;
 >    }
 >  
 >    public void force()
 > @@ -463,7 +461,7 @@
 >      throws IllegalAccessException
 >    {
 >      // We can use a fast copy if the size of a map has not changed.
 > -    if (this.elements == 0 && t.capacity == this.capacity
 > +    if (this.elements == 0 && t.internal_capacity == this.internal_capacity
 >  	&& t.length == this.length)
 >        {
 >  	this.buf.position(0);
 > @@ -528,7 +526,7 @@
 >      public Object next()
 >      {
 >        count--;
 > -      for (int i = idx; i < capacity; i++)
 > +      for (int i = idx; i < internal_capacity; i++)
 >          if (getKeyPos(i) != UNUSED_ENTRY)
 >            {
 >              idx = i+1;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]