1 /*
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
213 return;
214 }
215 if (DO_STATS) {
216 stats.returnOp++;
217 }
218 // fill cache:
219 if (arrays.length > tail) {
220 arrays[tail++] = array;
221
222 if (DO_STATS) {
223 stats.updateMaxSize(tail);
224 }
225 } else if (DO_CHECKS) {
226 logInfo(getLogPrefix(clean) + "ByteArrayCache: "
227 + "array capacity exceeded !");
228 }
229 }
230 }
231
232 static byte[] createArray(final int length, final boolean clean) {
233 if (clean) {
234 return new byte[length];
235 }
236 // use JDK9 Unsafe.allocateUninitializedArray(class, length):
237 return (byte[]) OffHeapArray.UNSAFE.allocateUninitializedArray(byte.class, length);
238 }
239
240 static void fill(final byte[] array, final int fromIndex,
241 final int toIndex, final byte value)
242 {
243 // clear array data:
244 Arrays.fill(array, fromIndex, toIndex, value);
245 if (DO_CHECKS) {
246 check(array, fromIndex, toIndex, value);
247 }
248 }
249
250 public static void check(final byte[] array, final int fromIndex,
251 final int toIndex, final byte value)
252 {
253 if (DO_CHECKS) {
254 // check zero on full array:
255 for (int i = 0; i < array.length; i++) {
256 if (array[i] != value) {
257 logException("Invalid value at: " + i + " = " + array[i]
|
1 /*
2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
213 return;
214 }
215 if (DO_STATS) {
216 stats.returnOp++;
217 }
218 // fill cache:
219 if (arrays.length > tail) {
220 arrays[tail++] = array;
221
222 if (DO_STATS) {
223 stats.updateMaxSize(tail);
224 }
225 } else if (DO_CHECKS) {
226 logInfo(getLogPrefix(clean) + "ByteArrayCache: "
227 + "array capacity exceeded !");
228 }
229 }
230 }
231
232 static byte[] createArray(final int length, final boolean clean) {
233 return new byte[length];
234 }
235
236 static void fill(final byte[] array, final int fromIndex,
237 final int toIndex, final byte value)
238 {
239 // clear array data:
240 Arrays.fill(array, fromIndex, toIndex, value);
241 if (DO_CHECKS) {
242 check(array, fromIndex, toIndex, value);
243 }
244 }
245
246 public static void check(final byte[] array, final int fromIndex,
247 final int toIndex, final byte value)
248 {
249 if (DO_CHECKS) {
250 // check zero on full array:
251 for (int i = 0; i < array.length; i++) {
252 if (array[i] != value) {
253 logException("Invalid value at: " + i + " = " + array[i]
|