Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 57321 invoked from network); 16 Jan 2008 13:53:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Jan 2008 13:53:19 -0000 Received: (qmail 62991 invoked by uid 500); 16 Jan 2008 13:53:08 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 62964 invoked by uid 500); 16 Jan 2008 13:53:08 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 62955 invoked by uid 99); 16 Jan 2008 13:53:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Jan 2008 05:53:08 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Jan 2008 13:52:52 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EECE11A983A; Wed, 16 Jan 2008 05:52:57 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r612458 - in /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200: BandSet.java CodecEncoding.java PopulationCodec.java Date: Wed, 16 Jan 2008 13:52:56 -0000 To: commits@harmony.apache.org From: tellison@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080116135257.EECE11A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tellison Date: Wed Jan 16 05:52:49 2008 New Revision: 612458 URL: http://svn.apache.org/viewvc?rev=612458&view=rev Log: Apply patch HARMONY-5392 ([classlib] [pack200] Population Codec doesn't always work properly) Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java?rev=612458&r1=612457&r2=612458&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java (original) +++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java Wed Jan 16 05:52:49 2008 @@ -19,6 +19,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; import org.apache.harmony.pack200.bytecode.CPClass; import org.apache.harmony.pack200.bytecode.CPDouble; @@ -359,9 +360,9 @@ /* * Note - this is not in the spec, but seems to be used as an * optimization by the RI for bands where the minimum and maximum values - * are known (ie reference bands). It will not hurt any encoding that is - * following the spec because all the values decoded will be inside the - * range anyway. + * are known (ie reference bands). It will not hurt any implementation + * that is following the spec because all the values decoded will be + * inside the range anyway. */ if (codecUsed instanceof BHSDCodec) { for (int i = 0; i < returnBand.length; i++) { @@ -370,6 +371,24 @@ } while (returnBand[i] > maxValue) { returnBand[i] -= ((BHSDCodec) codecUsed).cardinality(); + } + } + } else if (codecUsed instanceof PopulationCodec) { + PopulationCodec popCodec = (PopulationCodec)codecUsed; + long[] favoured = (long[]) popCodec.getFavoured().clone(); + Arrays.sort(favoured); + for (int i = 0; i < returnBand.length; i++) { + if(returnBand[i] < 0 || returnBand[i] > maxValue) { + boolean favouredValue = Arrays.binarySearch(favoured, returnBand[i]) > -1; + Codec theCodec = favouredValue ? popCodec.getFavouredCodec(): popCodec.getUnvafouredCodec(); + if(theCodec instanceof BHSDCodec) { + while (returnBand[i] < 0) { + returnBand[i] += ((BHSDCodec) theCodec).cardinality(); + } + while (returnBand[i] > maxValue) { + returnBand[i] -= ((BHSDCodec) theCodec).cardinality(); + } + } } } } Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java?rev=612458&r1=612457&r2=612458&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java (original) +++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java Wed Jan 16 05:52:49 2008 @@ -123,7 +123,7 @@ int h = code + 1; // This handles the special cases for invalid combinations of data. return new BHSDCodec(b,h,s,d); - } else if (value >= 117 && value <= 140) { + } else if (value >= 117 && value <= 140) { // Run codec int offset = value - 117; int kx = offset & 3; boolean kbflag = (offset >> 2 & 1) == 1; @@ -146,7 +146,7 @@ bCodec = getCodec(in.read(),in,defaultCodec); } return new RunCodec(k,aCodec,bCodec); - } else if (value >= 141 && value <= 188) { + } else if (value >= 141 && value <= 188) { // Population Codec int offset = value - 141; boolean fdef = (offset & 1) == 1; boolean udef = (offset >> 1 & 1) == 1; @@ -166,9 +166,9 @@ return new PopulationCodec(fCodec,l,uCodec); } else { Codec fCodec = (fdef ? defaultCodec : getCodec(in.read(),in,defaultCodec) ); + Codec tCodec = getCodec(in.read(),in,defaultCodec); Codec uCodec = (udef ? defaultCodec : getCodec(in.read(),in,defaultCodec) ); - Codec tCodec = getCodec(in.read(),in,defaultCodec); - return new PopulationCodec(fCodec,uCodec,tCodec); + return new PopulationCodec(fCodec,tCodec,uCodec); } } else { throw new Pack200Exception("Invalid codec encoding byte (" + value + ") found" ); Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java?rev=612458&r1=612457&r2=612458&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java (original) +++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java Wed Jan 16 05:52:49 2008 @@ -24,6 +24,7 @@ private Codec tokenCodec; private Codec unvafouredCodec; private int l; + private long[] favoured; public PopulationCodec(Codec favouredCodec, Codec tableCodec, Codec unvafouredCodec) { this.favouredCodec = favouredCodec; @@ -52,7 +53,7 @@ public long[] decode(int n, InputStream in) throws IOException, Pack200Exception { - long favoured[] = new long[n]; // there must be <= n values, but probably a lot less + favoured = new long[n]; // there must be <= n values, but probably a lot less long result[]; // read table of favorites first long smallest = Long.MAX_VALUE; @@ -71,7 +72,7 @@ // ensure that -X and +X -> +X smallest = Math.abs(smallest); } - } + } // if tokenCodec needs to be derived from the T, L and K values if (tokenCodec == null) { if (k < 256) { @@ -101,5 +102,17 @@ } } return result; + } + + public long[] getFavoured() { + return favoured; + } + + public Codec getFavouredCodec() { + return favouredCodec; + } + + public Codec getUnvafouredCodec() { + return unvafouredCodec; } }