/* * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * @test * @bug 6348045 6341887 8231770 * @summary GZipOutputStream/InputStream goes critical(calls JNI_Get*Critical) * and causes slowness. This test uses Deflater and Inflater directly. * @key randomness * @run main/othervm -Xcheck:jni FlaterTest
*/
/** * This test runs Inflater and Defalter in a number of simultaneous threads, * validating that the deflated & then inflated data matches the original * data.
*/ publicclass FlaterTest extendsThread { privatestaticfinalint DATA_LEN = 1024 * 128;
// If true, print extra info. privatestaticfinalboolean debug = false;
// Set of Flater threads running. privatestatic Set<Flater> flaters =
Collections.synchronizedSet(new HashSet<>());
/** Fill in {@code data} with random values. */ staticvoid createData() {
ByteBuffer bb = ByteBuffer.allocateDirect(DATA_LEN * 8); for (int i = 0; i < DATA_LEN * 8; i += 8) {
bb.putDouble(i, Math.random());
}
dataDirect = bb; final ByteBuffer hb = ByteBuffer.allocate(bb.capacity());
hb.duplicate().put(bb.duplicate());
dataHeap = hb; if (debug) System.out.println("data length is " + bb.capacity());
}
/** @return the length of the deflated {@code data}. */ privatestaticint getDeflatedLength() {
Deflater deflater = new Deflater();
deflater.setInput(dataDirect.duplicate());
deflater.finish(); byte[] out = newbyte[dataDirect.capacity()]; int rc = deflater.deflate(out);
deflater.end(); if (debug) System.out.println("deflatedLength is " + rc); return rc;
}
/** Compares given bytes with those in {@code data}. * @throws Exception if given bytes don't match {@code data}.
*/ privatestaticvoid validate(ByteBuffer buf, int offset, int len) throws Exception { for (int i = 0; i < len; i++ ) { if (buf.get(i) != dataDirect.get(offset+i)) { thrownew Exception("mismatch at " + (offset + i));
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.