Path: blob/master/test/hotspot/jtreg/compiler/c2/Test6732154.java
41149 views
/*1* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 673215426* @summary REG: Printing an Image using image/gif doc flavor crashes the VM, Solsparc27*28* @run main/othervm -Xcomp29* -XX:CompileCommand=compileonly,compiler.c2.Test6732154::ascii85Encode30* compiler.c2.Test673215431*/3233package compiler.c2;3435public class Test6732154 {3637// Exact copy of sun.print.PSPrinterJob.ascii85Encode([b)[b38private byte[] ascii85Encode(byte[] inArr) {39byte[] outArr = new byte[((inArr.length+4) * 5 / 4) + 2];40long p1 = 85;41long p2 = p1*p1;42long p3 = p1*p2;43long p4 = p1*p3;44byte pling = '!';4546int i = 0;47int olen = 0;48long val, rem;4950while (i+3 < inArr.length) {51val = ((long)((inArr[i++]&0xff))<<24) +52((long)((inArr[i++]&0xff))<<16) +53((long)((inArr[i++]&0xff))<< 8) +54((long)(inArr[i++]&0xff));55if (val == 0) {56outArr[olen++] = 'z';57} else {58rem = val;59outArr[olen++] = (byte)(rem / p4 + pling); rem = rem % p4;60outArr[olen++] = (byte)(rem / p3 + pling); rem = rem % p3;61outArr[olen++] = (byte)(rem / p2 + pling); rem = rem % p2;62outArr[olen++] = (byte)(rem / p1 + pling); rem = rem % p1;63outArr[olen++] = (byte)(rem + pling);64}65}66// input not a multiple of 4 bytes, write partial output.67if (i < inArr.length) {68int n = inArr.length - i; // n bytes remain to be written6970val = 0;71while (i < inArr.length) {72val = (val << 8) + (inArr[i++]&0xff);73}7475int append = 4 - n;76while (append-- > 0) {77val = val << 8;78}79byte []c = new byte[5];80rem = val;81c[0] = (byte)(rem / p4 + pling); rem = rem % p4;82c[1] = (byte)(rem / p3 + pling); rem = rem % p3;83c[2] = (byte)(rem / p2 + pling); rem = rem % p2;84c[3] = (byte)(rem / p1 + pling); rem = rem % p1;85c[4] = (byte)(rem + pling);8687for (int b = 0; b < n+1 ; b++) {88outArr[olen++] = c[b];89}90}9192// write EOD marker.93outArr[olen++]='~'; outArr[olen++]='>';9495/* The original intention was to insert a newline after every 78 bytes.96* This was mainly intended for legibility but I decided against this97* partially because of the (small) amount of extra space, and98* partially because for line breaks either would have to hardwire99* ascii 10 (newline) or calculate space in bytes to allocate for100* the platform's newline byte sequence. Also need to be careful101* about where its inserted:102* Ascii 85 decoder ignores white space except for one special case:103* you must ensure you do not split the EOD marker across lines.104*/105byte[] retArr = new byte[olen];106System.arraycopy(outArr, 0, retArr, 0, olen);107return retArr;108}109110public static void main(String[] args) {111new Test6732154().ascii85Encode(new byte[0]);112System.out.println("Test passed.");113}114}115116117