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
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
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.
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.
25 - * This source code is provided as is, without any express or implied warranty.
28 -package spec.benchmarks._201_compress;
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 */
35 /*****************************************************************/
37 +final class Hash_Table {
39 + private int size; /* for dynamic table sizing */
41 + public Hash_Table() {
42 + size = Compress.HSIZE;
43 + tab = new int[size];
46 + public int of(int i) {
50 + public void set(int i, int v) {
54 + public int hsize() {
58 + public void clear() {
61 + for (i = 0; i < size; i++) {
68 +/*****************************************************************/
70 final class Code_Table {
75 /*****************************************************************/
77 +final class Suffix_Table {
80 + public Suffix_Table () {
81 + tab = new byte[Compress.SUFFIX_TAB_SZ];
84 + public byte of(int i) {
88 + public void set(int i, byte v) {
92 + public void init(int size) {
94 + for ( code = 0; code < size; code++ ) {
95 + tab[code] = (byte)code;
101 +/*****************************************************************/
103 +final class De_Stack {
104 + private byte tab[];
107 + public De_Stack() {
108 + tab = new byte[Compress.STACK_SZ];
112 + public void push(byte c) {
116 + public byte pop() {
121 + public boolean is_empty() {
122 + return (index == 0);
127 +/*****************************************************************/
130 protected int n_bits; /* number of bits/code */
131 protected int maxbits; /* user settable max # bits/code */
133 checkpoint = CHECK_GAP;
134 free_ent = ((block_compress != 0) ? Compress.FIRST : 256 );
136 - htab = new Hash_Table(); // dm/kmd 4/10/98
137 + htab = new Hash_Table();
138 codetab = new Code_Table();
140 Output.putbyte(Compress.magic_header[0]);
141 @@ -296,15 +366,13 @@
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 ) {
149 + if ( htab.of (i) == fcode ) {
150 ent = codetab.of (i);
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) */
160 @@ -313,15 +381,11 @@
161 if ( (i -= disp) < 0 )
164 - temphtab = htab.of (i); // dm/kmd 4/15
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);
172 -// dm/kmd 4/15 } while ( htab.of (i) > 0 );
173 - } while ( temphtab > 0 ); // dm kmd 4/15
174 + } while ( htab.of (i) > 0 );
179 output ( (int) Compress.CLEAR );
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
188 - protected int tab[]; // for dynamic table sizing */
189 - protected int size;
191 - public Hash_Table() {
192 - size = Compress.HSIZE;
193 - tab = new int[size];
196 - public int of(int i) {
200 - public void set(int i, int v) {
204 - public int hsize() {
208 - public void clear() {
211 - for (i = 0; i < size; i++) {
225 -/*****************************************************************/
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
232 - protected byte tab[];
233 - protected int index;
235 - public De_Stack() {
236 - tab = new byte[Compress.STACK_SZ];
240 - public void push(byte c) {
244 - public byte pop() {
249 - public boolean is_empty() {
250 - return (index == 0);
254 -/*****************************************************************/
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
261 - protected byte tab[];
263 - public Suffix_Table () {
264 - tab = new byte[Compress.SUFFIX_TAB_SZ];
267 - public byte of(int i) {
271 - public void set(int i, byte v) {
275 - public void init(int size) {
277 - for ( code = 0; code < size; code++ ) {
278 - tab[code] = (byte)code;
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
290 * This source code is provided as is, without any express or implied warranty.
293 -package spec.benchmarks._201_compress;
294 -import spec.harness.*;
296 -public class Main implements SpecBenchmark {
300 static long runBenchmark( String[] args ) {
302 - int speed = spec.harness.Context.getSpeed();
305 if( args.length == 0 ) {
311 - return new Harness().inst_main( args );
312 + return new MyCompress().inst_main( args );
316 public static void main( String[] args ) {
317 runBenchmark( args );
321 - public long harnessMain( String[] args ) {
322 - return runBenchmark( args );
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
332 + * @(#)Harness.java 1.14 06/26/98
334 + * Copyright (c) 1998 Standard Performance Evaluation Corporation (SPEC)
335 + * All rights reserved.
336 + * Copyright (c) 1997,1998 Sun Microsystems, Inc. All rights reserved.
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.
344 +public final class MyCompress
347 + final static int COMPRESS = 0;
348 + final static int UNCOMPRESS = 1;
350 + private byte orig_text_buffer[];
351 + private byte comp_text_buffer[];
353 + private int fill_text_buffer(String infile) {
359 + java.io.FileInputStream sif = new java.io.FileInputStream(infile);
360 + java.io.File myfile = new File(infile);
361 + num_bytes = (int) myfile.length();
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
369 + orig_text_buffer = new byte[num_bytes];
370 + comp_text_buffer = new byte[num_bytes];
373 + while ( (bytes_read = sif.read(orig_text_buffer, act , (num_bytes - act))) > 0){
374 + act = act + bytes_read;
377 + sif.close(); // release resources
379 + if ( act != num_bytes ) {
380 + System.out.println("ERROR reading test input file");
383 + catch (IOException e) {
384 + System.out.println("ERROR opening/accessing input file: "+infile);
391 + public MyCompress() {
393 + orig_text_buffer = new byte[BUFFERSIZE];
394 + comp_text_buffer = new byte[BUFFERSIZE];
395 + new_text_buffer = new byte[BUFFERSIZE];
399 + public boolean run_compress(String[] args) {
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
406 + System.out.println( "Loop count = " + loopct );
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
412 + System.out.println( count); // write input file size
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
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
424 + if ( new_count != count ) {
425 + System.out.println ("Error : Number of Bytes should have been " + count + " instead of " + new_count);
428 + // Release resources to prevent resource leak
429 + orig_text_buffer = null;
431 + comp_text_buffer = null;
437 + public long inst_main( String[] argv ) {
439 + long startTime = System.currentTimeMillis();
441 + if (!run_compress(argv))
444 + return System.currentTimeMillis() - startTime;
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
454 - * @(#)Harness.java 1.14 06/26/98
456 - * Copyright (c) 1998 Standard Performance Evaluation Corporation (SPEC)
457 - * All rights reserved.
458 - * Copyright (c) 1997,1998 Sun Microsystems, Inc. All rights reserved.
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.
464 -package spec.benchmarks._201_compress;
465 -import spec.harness.*;
469 -public final class Harness
472 - final static int COMPRESS = 0;
473 - final static int UNCOMPRESS = 1;
475 - private byte orig_text_buffer[];
476 - private byte comp_text_buffer[];
478 - private int fill_text_buffer(String infile) {
484 - spec.io.FileInputStream sif = new spec.io.FileInputStream(infile);
485 - num_bytes = (int)sif.getContentLength();
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
493 - orig_text_buffer = new byte[num_bytes];
494 - comp_text_buffer = new byte[num_bytes];
497 - while ( (bytes_read = sif.read(orig_text_buffer, act , (num_bytes - act))) > 0){
498 - act = act + bytes_read;
501 - sif.close(); // release resources
503 - if ( act != num_bytes )
505 - spec.harness.Context.out.println("ERROR reading test input file");
508 - catch (IOException e)
510 - spec.harness.Context.out.println("ERROR opening/accessing input file: "+infile);
519 - orig_text_buffer = new byte[BUFFERSIZE];
520 - comp_text_buffer = new byte[BUFFERSIZE];
521 - new_text_buffer = new byte[BUFFERSIZE];
525 - public boolean run_compress(String[] args) {
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
532 - spec.harness.Context.out.println( "Loop count = " + loopct );
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
538 - spec.harness.Context.out.println( count); // write input file size
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
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
550 - if ( new_count != count ) {
551 - spec.harness.Context.out.println ("Error : Number of Bytes should have been " + count + " instead of " + new_count);
554 - // Release resources tor prevent resource leak
555 - orig_text_buffer = null;
556 - comp_text_buffer = null;
563 - public long inst_main( String[] argv ) {
565 - long startTime = System.currentTimeMillis();
567 - if (!run_compress(argv))
570 - return System.currentTimeMillis() - startTime;