*** empty log message ***
[cacao.git] / tests / jvm98 / compress.diff
1 diff -u compress1/Compress.java compress/Compress.java
2 --- compress1/Compress.java     Wed Jun 17 22:14:24 1998
3 +++ compress/Compress.java      Fri Oct 25 11:47:20 2002
4 @@ -1,15 +1,4 @@
5  /*
6 - *  Used 'Inner Classes' to minimize temptations of JVM exploiting low hanging
7 - *  fruits. 'Inner classes' are defined in appendix D of the 'Java Programming
8 - *  Language' by Ken Arnold.
9 - *  - We moved the class declaration, unchanged, of Hash_Table to within the
10 - *    class declaration of Compressor.
11 - *  - We moved the class declarations, unchanged, of De_Stack and
12 -      Suffix_Table to within the class declaration of Decompressor.
13 - *  - pre-computed trivial htab(i) to minimize millions of trivial calls
14 - *  - Don McCauley (IBM), Kaivalya 4/16/98
15 - *
16 - *   @(#)Compress.java 1.7 06/17/98
17   *  // Don McCauley/kmd  - IBM 02/26/98
18   *  // getbyte and getcode fixed -- kaivalya & Don
19   * compress.c - File compression ala IEEE Computer, June 1984.
20 @@ -29,12 +18,8 @@
21   * substrings and replaces them with a variable size code.  This is
22   * deterministic, and can be done on the fly.  Thus, the decompression
23   * procedure needs no input table, but tracks the way the table was built.
24 - *
25 - * This source code is provided as is, without any express or implied warranty.
26   */
27  
28 -package spec.benchmarks._201_compress;
29 -
30  final class Compress {
31      final static int BITS = 16;                /* always set to 16 for SPEC95 */
32      final static int INIT_BITS = 9;    /* initial number of bits/code */
33 @@ -162,6 +147,39 @@
34  
35  /*****************************************************************/
36  
37 +final class Hash_Table {
38 +    private int tab[];
39 +    private int size;                  /* for dynamic table sizing */
40 +
41 +    public Hash_Table() {
42 +       size = Compress.HSIZE;
43 +       tab = new int[size];
44 +    }
45 +
46 +    public int of(int i) {
47 +       return tab[i];
48 +    }
49 +
50 +    public void set(int i, int v) {
51 +       tab[i] = v;
52 +    }
53 +
54 +    public int hsize() {
55 +       return size;
56 +    }
57 +
58 +    public void clear() {
59 +       int i;
60 +
61 +       for (i = 0; i < size; i++) {
62 +           tab[i] = -1;
63 +       }
64 +    }
65 +};
66 +
67 +
68 +/*****************************************************************/
69 +
70  final class Code_Table {
71      private short tab[];
72  
73 @@ -188,6 +206,58 @@
74  
75  /*****************************************************************/
76  
77 +final class Suffix_Table {
78 +    private byte tab[];
79 +
80 +    public Suffix_Table () {
81 +       tab = new byte[Compress.SUFFIX_TAB_SZ];
82 +    }
83 +
84 +    public byte of(int i) {
85 +       return tab[i];
86 +    }
87 +
88 +    public void set(int i, byte v) {
89 +       tab[i] = v;
90 +    }
91 +
92 +    public void init(int size) {
93 +       int code;
94 +       for ( code = 0; code < size; code++ ) {
95 +           tab[code] = (byte)code;
96 +       }
97 +    }
98 +};
99 +
100 +
101 +/*****************************************************************/
102 +
103 +final class De_Stack {
104 +    private byte tab[];
105 +    private int index;
106 +
107 +    public De_Stack() {
108 +       tab = new byte[Compress.STACK_SZ];
109 +       index = 0;
110 +    }
111 +
112 +    public void push(byte c) {
113 +       tab[index++] = c;
114 +    }
115 +
116 +    public byte pop() {
117 +       index--;
118 +       return tab[index];
119 +    }
120 +
121 +    public boolean is_empty() {
122 +       return (index == 0);
123 +    }
124 +};
125 +
126 +
127 +/*****************************************************************/
128 +
129  class Comp_Base {
130      protected int n_bits;              /* number of bits/code */
131      protected int maxbits;             /* user settable max # bits/code */
132 @@ -264,7 +334,7 @@
133         checkpoint = CHECK_GAP;
134         free_ent = ((block_compress != 0) ? Compress.FIRST : 256 );
135  
136 -       htab = new Hash_Table();  // dm/kmd 4/10/98
137 +       htab = new Hash_Table();
138         codetab = new Code_Table();
139  
140         Output.putbyte(Compress.magic_header[0]);
141 @@ -296,15 +366,13 @@
142             in_count++;
143             fcode = (((int) c << maxbits) + ent);
144             i = ((c << hshift) ^ ent);  /* xor hashing */
145 -            int temphtab = htab.of (i);  // dm/kmd 4/15
146 -//dm kmd           if ( htab.of (i) == fcode ) {  // dm/kmd 4/15
147 -           if ( temphtab == fcode ) {
148 +
149 +           if ( htab.of (i) == fcode ) {
150                 ent = codetab.of (i);
151                 continue next_byte;
152             }
153  
154 -//dm kmd 4/15      if ( htab.of (i) >= 0 ) {   /* non-empty slot */
155 -           if ( temphtab >= 0 ) {      /* non-empty slot  dm kmd 4/15*/
156 +           if ( htab.of (i) >= 0 ) {   /* non-empty slot */
157                 disp = hsize_reg - i;   /* secondary hash (after G. Knott) */
158                 if ( i == 0 )
159                     disp = 1;
160 @@ -313,15 +381,11 @@
161                     if ( (i -= disp) < 0 )
162                         i += hsize_reg;
163  
164 -                     temphtab = htab.of (i);  // dm/kmd 4/15
165 -                   
166 -// dm/kmd 4/15     if ( htab.of (i) == fcode ) {
167 -                   if ( temphtab == fcode ) {
168 +                   if ( htab.of (i) == fcode ) {
169                         ent = codetab.of (i);
170                         continue next_byte;
171                     }
172 -// dm/kmd 4/15         } while ( htab.of (i) > 0 );
173 -               } while ( temphtab > 0 );              // dm kmd 4/15
174 +               } while ( htab.of (i) > 0 );
175             }
176  
177             output ( ent );
178 @@ -463,41 +527,6 @@
179             output ( (int) Compress.CLEAR );
180         }
181      }
182 -
183 -final class Hash_Table {                 // moved 4/15/98 dm/kmd
184 -/* Use protected instead of private
185 - * to allow access by parent class
186 - * of inner class. wnb 4/17/98
187 - */
188 -    protected int tab[];               // for dynamic table sizing */
189 -    protected int size;        
190 -
191 -    public Hash_Table() {
192 -       size = Compress.HSIZE;
193 -       tab = new int[size];
194 -    }
195 -
196 -    public int of(int i) {
197 -       return tab[i];
198 -    }
199 -
200 -    public void set(int i, int v) {
201 -       tab[i] = v;
202 -    }
203 -
204 -    public int hsize() {
205 -       return size;
206 -    }
207 -
208 -    public void clear() {
209 -       int i;
210 -
211 -       for (i = 0; i < size; i++) {
212 -           tab[i] = -1;
213 -       }
214 -    }
215 -};
216 -
217  };
218  
219  
220 @@ -678,65 +707,6 @@
221  
222         return code;
223      }
224 -
225 -/*****************************************************************/
226 -
227 -final class De_Stack {                         // moved 4/15/98 dm/kmd
228 -/* Use protected instead of private
229 - * to allow access by parent class
230 - * of inner class. wnb 4/17/98
231 - */
232 -    protected byte tab[];
233 -    protected int index;
234 -
235 -    public De_Stack() {
236 -       tab = new byte[Compress.STACK_SZ];
237 -       index = 0;
238 -    }
239 -
240 -    public void push(byte c) {
241 -       tab[index++] = c;
242 -    }
243 -
244 -    public byte pop() {
245 -       index--;
246 -       return tab[index];
247 -    }
248 -
249 -    public boolean is_empty() {
250 -       return (index == 0);
251 -    }
252 -};
253 -
254 -/*****************************************************************/
255 -
256 -final class Suffix_Table {                     // moved 4/15/98 dm/kmd
257 -/* Use protected instead of private
258 - * to allow access by parent class
259 - * of inner class. wnb 4/17/98
260 - */
261 -    protected byte tab[];
262 -
263 -    public Suffix_Table () {
264 -       tab = new byte[Compress.SUFFIX_TAB_SZ];
265 -    }
266 -
267 -    public byte of(int i) {
268 -       return tab[i];
269 -    }
270 -
271 -    public void set(int i, byte v) {
272 -       tab[i] = v;
273 -    }
274 -
275 -    public void init(int size) {
276 -       int code;
277 -       for ( code = 0; code < size; code++ ) {
278 -           tab[code] = (byte)code;
279 -       }
280 -    }
281 -};
282 -
283  };
284  
285  
286 diff -u compress1/Main.java compress/Main.java
287 --- compress1/Main.java Fri Jun 26 21:42:33 1998
288 +++ compress/Main.java  Mon Nov 30 18:39:00 1998
289 @@ -6,15 +6,12 @@
290   * This source code is provided as is, without any express or implied warranty.
291   */
292  
293 -package spec.benchmarks._201_compress;
294 -import spec.harness.*;
295 -
296 -public class Main implements SpecBenchmark {
297 +public class Main {
298  
299  
300      static long runBenchmark( String[] args ) {
301  
302 -     int speed = spec.harness.Context.getSpeed();
303 +     int speed = 100;
304  
305          if( args.length == 0 ) {
306  
307 @@ -46,18 +43,11 @@
308                                }        
309                                   }
310  
311 -       return new Harness().inst_main( args );
312 +       return new MyCompress().inst_main( args );
313      }
314  
315  
316      public static void main( String[] args ) {          
317          runBenchmark( args );
318      }
319 -
320 -    
321 -    public long harnessMain( String[] args ) {
322 -        return runBenchmark( args );
323 -    }
324 -
325 -  
326  }
327 diff -Nu compress1/MyCompress.java compress/MyCompress.java
328 --- compress1/MyCompress.java   Thu Jan  1 01:00:00 1970
329 +++ compress/MyCompress.java    Fri Oct 25 22:01:30 2002
330 @@ -0,0 +1,118 @@
331 +/*
332 + * @(#)Harness.java    1.14 06/26/98
333 + *
334 + * Copyright (c) 1998 Standard Performance Evaluation Corporation (SPEC)
335 + *               All rights reserved.
336 + * Copyright (c) 1997,1998 Sun Microsystems, Inc. All rights reserved.
337 + *
338 + * Modified by Kaivalya M. Dixit & Don McCauley (IBM) to read input files
339 + * This source code is provided as is, without any express or implied warranty.
340 + */
341 +
342 +import java.io.*;
343 +
344 +public final class MyCompress
345 +{
346 +
347 +       final static int COMPRESS = 0;
348 +       final static int UNCOMPRESS = 1;
349 +
350 +       private byte orig_text_buffer[];
351 +       private byte comp_text_buffer[];
352 +
353 +       private int fill_text_buffer(String infile) {
354 +               int act = 0;
355 +               int num_bytes = 0;
356 +
357 +               try {
358 +
359 +                       java.io.FileInputStream sif = new java.io.FileInputStream(infile);
360 +                       java.io.File myfile = new File(infile);
361 +                       num_bytes = (int) myfile.length();
362 +
363 +                       // Only allocate size of input file rather than MAX - kmd
364 +                       // If compressed file is larger than input file this allocation 
365 +                       // will fail and out of bound exception will occur 
366 +                       // In real lie, compress will no do any compression as no
367 +                       // space is saved.-- kaivalya
368 +
369 +                       orig_text_buffer = new byte[num_bytes];
370 +                       comp_text_buffer = new byte[num_bytes];  
371 +
372 +                       int bytes_read;
373 +                       while ( (bytes_read = sif.read(orig_text_buffer, act , (num_bytes - act))) > 0){
374 +                               act = act +  bytes_read;
375 +                               }
376 +
377 +                       sif.close();    // release resources 
378 +
379 +                       if ( act != num_bytes ) {
380 +                               System.out.println("ERROR reading test input file");
381 +                               }
382 +                       }
383 +               catch (IOException e) {
384 +                       System.out.println("ERROR opening/accessing input file: "+infile);
385 +                       };
386 +
387 +               return act;
388 +               }
389 +
390 +
391 +       public MyCompress() {
392 +               /*
393 +               orig_text_buffer = new byte[BUFFERSIZE];
394 +               comp_text_buffer = new byte[BUFFERSIZE];
395 +               new_text_buffer = new byte[BUFFERSIZE];
396 +               */
397 +               }
398 +
399 +       public boolean run_compress(String[] args) {
400 +               int count = 0;
401 +               int i, oper;
402 +               int comp_count, new_count;
403 +               int fn = Integer.parseInt(args [0] );     // get number of files
404 +               int loopct = Integer.parseInt(args [1] ); // get loop count
405 +
406 +               System.out.println( "Loop count = " + loopct );
407 +
408 +               for (int cntr=0; cntr < loopct; cntr++ )           // iterate over
409 +                       for (int j=0; j < fn ; j++) {                      // number of files
410 +                               count = fill_text_buffer( args [j+2] );    // give file names to read
411 +                               oper=COMPRESS;
412 +                               System.out.println( count);  // write input file size
413 +
414 +                               // uncompress in the original text buffer.
415 +                               comp_count=Compress.spec_select_action(orig_text_buffer, count,
416 +                               oper, comp_text_buffer);
417 +                               System.out.println( comp_count); // write compressed file size
418 +
419 +                               oper=UNCOMPRESS;
420 +                               new_count=Compress.spec_select_action(comp_text_buffer, comp_count,
421 +                               oper, orig_text_buffer); 
422 +                               // if uncompressed files size is not same as the original ERROR
423 +
424 +                               if ( new_count != count ) {
425 +                                       System.out.println ("Error : Number of Bytes should have been  " + count + " instead of " + new_count);
426 +                                       }
427 +
428 +                               // Release resources to prevent resource leak
429 +                               orig_text_buffer = null;
430 +
431 +                               comp_text_buffer = null;
432 +                               }
433 +               return true;
434 +               }
435 +
436 +
437 +       public long inst_main( String[] argv ) {         
438 +
439 +               long startTime = System.currentTimeMillis();
440 +
441 +               if (!run_compress(argv))
442 +               return 0;
443 +
444 +               return System.currentTimeMillis() - startTime;
445 +               }
446 +
447 +}
448 +
449 diff -Nu compress1/Harness.java compress/Harness.java
450 --- compress1/Harness.java      Fri Jun 26 21:36:51 1998
451 +++ compress/Harness.java       Thu Jan  1 01:00:00 1970
452 @@ -1,122 +0,0 @@
453 -/*
454 - * @(#)Harness.java    1.14 06/26/98
455 - *
456 - * Copyright (c) 1998 Standard Performance Evaluation Corporation (SPEC)
457 - *               All rights reserved.
458 - * Copyright (c) 1997,1998 Sun Microsystems, Inc. All rights reserved.
459 - *
460 - * Modified by Kaivalya M. Dixit & Don McCauley (IBM) to read input files
461 - * This source code is provided as is, without any express or implied warranty.
462 - */
463 -
464 -package spec.benchmarks._201_compress;
465 -import spec.harness.*;
466 -
467 -import java.io.*;
468 -
469 -public final class Harness
470 -{
471 -
472 -    final static int COMPRESS = 0;
473 -    final static int UNCOMPRESS = 1;
474 -
475 -    private byte orig_text_buffer[];
476 -    private byte comp_text_buffer[];
477 -
478 -    private int fill_text_buffer(String infile) {
479 -      int act = 0;
480 -      int num_bytes = 0;
481 -       
482 -      try {
483 -               
484 -        spec.io.FileInputStream sif = new spec.io.FileInputStream(infile);
485 -        num_bytes = (int)sif.getContentLength();
486 -        
487 -        // Only allocate size of input file rather than MAX - kmd
488 -        // If compressed file is larger than input file this allocation 
489 -       // will fail and out of bound exception will occur 
490 -       // In real lie, compress will no do any compression as no
491 -       // space is saved.-- kaivalya
492 -       
493 -       orig_text_buffer = new byte[num_bytes];
494 -       comp_text_buffer = new byte[num_bytes];  
495 -
496 -       int bytes_read;
497 -        while ( (bytes_read = sif.read(orig_text_buffer, act , (num_bytes - act))) > 0){
498 -          act = act +  bytes_read;
499 -        }
500 -
501 -        sif.close();    // release resources 
502 -        
503 -        if ( act != num_bytes )
504 -            {
505 -            spec.harness.Context.out.println("ERROR reading test input file");
506 -            }
507 -      }
508 -      catch (IOException e)
509 -         {
510 -        spec.harness.Context.out.println("ERROR opening/accessing input file: "+infile);
511 -         };
512 -
513 -      return act;
514 -      }
515 -
516 -
517 -    public Harness() {
518 -       /*
519 -       orig_text_buffer = new byte[BUFFERSIZE];
520 -       comp_text_buffer = new byte[BUFFERSIZE];
521 -       new_text_buffer = new byte[BUFFERSIZE];
522 -       */
523 -    }
524 -
525 -    public boolean run_compress(String[] args) {
526 -       int count = 0;
527 -       int i, oper;
528 -       int comp_count, new_count;
529 -       int fn = Integer.parseInt(args [0] );     // get number of files
530 -       int loopct = Integer.parseInt(args [1] ); // get loop count
531 -
532 -    spec.harness.Context.out.println( "Loop count = " + loopct );
533 -
534 -    for (int cntr=0; cntr < loopct; cntr++ )  // iterate over
535 -     for (int j=0; j < fn ; j++)            { // number of files
536 -     count = fill_text_buffer( args [j+2] );  // give file names to read
537 -     oper=COMPRESS;
538 -     spec.harness.Context.out.println( count);  // write input file size
539 -     
540 -     // uncompress in the original text buffer.
541 -     comp_count=Compress.spec_select_action(orig_text_buffer, count,
542 -                                  oper, comp_text_buffer);
543 -     spec.harness.Context.out.println( comp_count); // write compressed file size
544 -       
545 -     oper=UNCOMPRESS;
546 -     new_count=Compress.spec_select_action(comp_text_buffer, comp_count,
547 -                                 oper, orig_text_buffer); 
548 -     // if uncompressed files size is not same as the original ERROR
549 -
550 -     if ( new_count != count ) {
551 -          spec.harness.Context.out.println ("Error : Number of Bytes should have been  " + count + " instead of " + new_count);
552 -           }
553 -
554 -         // Release resources tor prevent  resource leak
555 -         orig_text_buffer = null;
556 -        comp_text_buffer = null;
557 -       
558 -    }
559 -       return true;
560 -    }
561 -               
562 -
563 -    public long inst_main( String[] argv ) { 
564 -
565 -        long startTime = System.currentTimeMillis();
566 -    
567 -        if (!run_compress(argv))
568 -            return 0;
569 -        
570 -        return System.currentTimeMillis() - startTime;
571 -    }
572 -
573 -}
574 -