Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/compiler/6732154/Test6732154.java
32285 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*22*/2324/**25* @test26* @bug 673215427* @summary REG: Printing an Image using image/gif doc flavor crashes the VM, Solsparc28*29* @run main/othervm -Xcomp -XX:CompileOnly="Test6732154::ascii85Encode" Test673215430*/31public class Test6732154 {3233// Exact copy of sun.print.PSPrinterJob.ascii85Encode([b)[b34private byte[] ascii85Encode(byte[] inArr) {35byte[] outArr = new byte[((inArr.length+4) * 5 / 4) + 2];36long p1 = 85;37long p2 = p1*p1;38long p3 = p1*p2;39long p4 = p1*p3;40byte pling = '!';4142int i = 0;43int olen = 0;44long val, rem;4546while (i+3 < inArr.length) {47val = ((long)((inArr[i++]&0xff))<<24) +48((long)((inArr[i++]&0xff))<<16) +49((long)((inArr[i++]&0xff))<< 8) +50((long)(inArr[i++]&0xff));51if (val == 0) {52outArr[olen++] = 'z';53} else {54rem = val;55outArr[olen++] = (byte)(rem / p4 + pling); rem = rem % p4;56outArr[olen++] = (byte)(rem / p3 + pling); rem = rem % p3;57outArr[olen++] = (byte)(rem / p2 + pling); rem = rem % p2;58outArr[olen++] = (byte)(rem / p1 + pling); rem = rem % p1;59outArr[olen++] = (byte)(rem + pling);60}61}62// input not a multiple of 4 bytes, write partial output.63if (i < inArr.length) {64int n = inArr.length - i; // n bytes remain to be written6566val = 0;67while (i < inArr.length) {68val = (val << 8) + (inArr[i++]&0xff);69}7071int append = 4 - n;72while (append-- > 0) {73val = val << 8;74}75byte []c = new byte[5];76rem = val;77c[0] = (byte)(rem / p4 + pling); rem = rem % p4;78c[1] = (byte)(rem / p3 + pling); rem = rem % p3;79c[2] = (byte)(rem / p2 + pling); rem = rem % p2;80c[3] = (byte)(rem / p1 + pling); rem = rem % p1;81c[4] = (byte)(rem + pling);8283for (int b = 0; b < n+1 ; b++) {84outArr[olen++] = c[b];85}86}8788// write EOD marker.89outArr[olen++]='~'; outArr[olen++]='>';9091/* The original intention was to insert a newline after every 78 bytes.92* This was mainly intended for legibility but I decided against this93* partially because of the (small) amount of extra space, and94* partially because for line breaks either would have to hardwire95* ascii 10 (newline) or calculate space in bytes to allocate for96* the platform's newline byte sequence. Also need to be careful97* about where its inserted:98* Ascii 85 decoder ignores white space except for one special case:99* you must ensure you do not split the EOD marker across lines.100*/101byte[] retArr = new byte[olen];102System.arraycopy(outArr, 0, retArr, 0, olen);103return retArr;104}105106public static void main(String[] args) {107new Test6732154().ascii85Encode(new byte[0]);108System.out.println("Test passed.");109}110}111112113