author | lbourges |
Wed, 17 May 2017 22:05:11 +0200 | |
changeset 47126 | 188ef162f019 |
parent 40421 | d5ee65e2b0fb |
permissions | -rw-r--r-- |
34417 | 1 |
/* |
47126 | 2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
34417 | 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 |
|
23 |
* questions. |
|
24 |
*/ |
|
47126 | 25 |
|
34417 | 26 |
package sun.java2d.marlin; |
27 |
||
40421
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
28 |
import static sun.java2d.marlin.ArrayCacheConst.ARRAY_SIZES; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
29 |
import static sun.java2d.marlin.ArrayCacheConst.BUCKETS; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
30 |
import static sun.java2d.marlin.ArrayCacheConst.MAX_ARRAY_SIZE; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
31 |
import static sun.java2d.marlin.MarlinUtils.logInfo; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
32 |
import static sun.java2d.marlin.MarlinUtils.logException; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
33 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
34 |
import java.lang.ref.WeakReference; |
34417 | 35 |
import java.util.Arrays; |
40421
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
36 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
37 |
import sun.java2d.marlin.ArrayCacheConst.BucketStats; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
38 |
import sun.java2d.marlin.ArrayCacheConst.CacheStats; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
39 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
40 |
/* |
47126 | 41 |
* Note that the [BYTE/INT/FLOAT/DOUBLE]ArrayCache files are nearly identical except |
40421
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
42 |
* for a few type and name differences. Typically, the [BYTE]ArrayCache.java file |
47126 | 43 |
* is edited manually and then [INT/FLOAT/DOUBLE]ArrayCache.java |
40421
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
44 |
* files are generated with the following command lines: |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
45 |
*/ |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
46 |
// % sed -e 's/(b\yte)[ ]*//g' -e 's/b\yte/int/g' -e 's/B\yte/Int/g' < B\yteArrayCache.java > IntArrayCache.java |
47126 | 47 |
// % sed -e 's/(b\yte)[ ]*0/0.0f/g' -e 's/(b\yte)[ ]*/(float) /g' -e 's/b\yte/float/g' -e 's/B\yte/Float/g' < B\yteArrayCache.java > FloatArrayCache.java |
48 |
// % sed -e 's/(b\yte)[ ]*0/0.0d/g' -e 's/(b\yte)[ ]*/(double) /g' -e 's/b\yte/double/g' -e 's/B\yte/Double/g' < B\yteArrayCache.java > DoubleArrayCache.java |
|
34417 | 49 |
|
50 |
final class ByteArrayCache implements MarlinConst { |
|
51 |
||
40421
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
52 |
final boolean clean; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
53 |
private final int bucketCapacity; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
54 |
private WeakReference<Bucket[]> refBuckets = null; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
55 |
final CacheStats stats; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
56 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
57 |
ByteArrayCache(final boolean clean, final int bucketCapacity) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
58 |
this.clean = clean; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
59 |
this.bucketCapacity = bucketCapacity; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
60 |
this.stats = (DO_STATS) ? |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
61 |
new CacheStats(getLogPrefix(clean) + "ByteArrayCache") : null; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
62 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
63 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
64 |
Bucket getCacheBucket(final int length) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
65 |
final int bucket = ArrayCacheConst.getBucket(length); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
66 |
return getBuckets()[bucket]; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
67 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
68 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
69 |
private Bucket[] getBuckets() { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
70 |
// resolve reference: |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
71 |
Bucket[] buckets = (refBuckets != null) ? refBuckets.get() : null; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
72 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
73 |
// create a new buckets ? |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
74 |
if (buckets == null) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
75 |
buckets = new Bucket[BUCKETS]; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
76 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
77 |
for (int i = 0; i < BUCKETS; i++) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
78 |
buckets[i] = new Bucket(clean, ARRAY_SIZES[i], bucketCapacity, |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
79 |
(DO_STATS) ? stats.bucketStats[i] : null); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
80 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
81 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
82 |
// update weak reference: |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
83 |
refBuckets = new WeakReference<Bucket[]>(buckets); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
84 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
85 |
return buckets; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
86 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
87 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
88 |
Reference createRef(final int initialSize) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
89 |
return new Reference(this, initialSize); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
90 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
91 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
92 |
static final class Reference { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
93 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
94 |
// initial array reference (direct access) |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
95 |
final byte[] initial; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
96 |
private final boolean clean; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
97 |
private final ByteArrayCache cache; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
98 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
99 |
Reference(final ByteArrayCache cache, final int initialSize) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
100 |
this.cache = cache; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
101 |
this.clean = cache.clean; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
102 |
this.initial = createArray(initialSize, clean); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
103 |
if (DO_STATS) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
104 |
cache.stats.totalInitial += initialSize; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
105 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
106 |
} |
34417 | 107 |
|
40421
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
108 |
byte[] getArray(final int length) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
109 |
if (length <= MAX_ARRAY_SIZE) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
110 |
return cache.getCacheBucket(length).getArray(); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
111 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
112 |
if (DO_STATS) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
113 |
cache.stats.oversize++; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
114 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
115 |
if (DO_LOG_OVERSIZE) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
116 |
logInfo(getLogPrefix(clean) + "ByteArrayCache: " |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
117 |
+ "getArray[oversize]: length=\t" + length); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
118 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
119 |
return createArray(length, clean); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
120 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
121 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
122 |
byte[] widenArray(final byte[] array, final int usedSize, |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
123 |
final int needSize) |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
124 |
{ |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
125 |
final int length = array.length; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
126 |
if (DO_CHECKS && length >= needSize) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
127 |
return array; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
128 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
129 |
if (DO_STATS) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
130 |
cache.stats.resize++; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
131 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
132 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
133 |
// maybe change bucket: |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
134 |
// ensure getNewSize() > newSize: |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
135 |
final byte[] res = getArray(ArrayCacheConst.getNewSize(usedSize, needSize)); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
136 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
137 |
// use wrapper to ensure proper copy: |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
138 |
System.arraycopy(array, 0, res, 0, usedSize); // copy only used elements |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
139 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
140 |
// maybe return current array: |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
141 |
putArray(array, 0, usedSize); // ensure array is cleared |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
142 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
143 |
if (DO_LOG_WIDEN_ARRAY) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
144 |
logInfo(getLogPrefix(clean) + "ByteArrayCache: " |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
145 |
+ "widenArray[" + res.length |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
146 |
+ "]: usedSize=\t" + usedSize + "\tlength=\t" + length |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
147 |
+ "\tneeded length=\t" + needSize); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
148 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
149 |
return res; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
150 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
151 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
152 |
byte[] putArray(final byte[] array) |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
153 |
{ |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
154 |
// dirty array helper: |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
155 |
return putArray(array, 0, array.length); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
156 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
157 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
158 |
byte[] putArray(final byte[] array, final int fromIndex, |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
159 |
final int toIndex) |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
160 |
{ |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
161 |
if (array.length <= MAX_ARRAY_SIZE) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
162 |
if ((clean || DO_CLEAN_DIRTY) && (toIndex != 0)) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
163 |
// clean-up array of dirty part[fromIndex; toIndex[ |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
164 |
fill(array, fromIndex, toIndex, (byte)0); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
165 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
166 |
// ensure to never store initial arrays in cache: |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
167 |
if (array != initial) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
168 |
cache.getCacheBucket(array.length).putArray(array); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
169 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
170 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
171 |
return initial; |
34417 | 172 |
} |
173 |
} |
|
174 |
||
40421
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
175 |
static final class Bucket { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
176 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
177 |
private int tail = 0; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
178 |
private final int arraySize; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
179 |
private final boolean clean; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
180 |
private final byte[][] arrays; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
181 |
private final BucketStats stats; |
34417 | 182 |
|
40421
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
183 |
Bucket(final boolean clean, final int arraySize, |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
184 |
final int capacity, final BucketStats stats) |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
185 |
{ |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
186 |
this.arraySize = arraySize; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
187 |
this.clean = clean; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
188 |
this.stats = stats; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
189 |
this.arrays = new byte[capacity][]; |
34417 | 190 |
} |
191 |
||
40421
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
192 |
byte[] getArray() { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
193 |
if (DO_STATS) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
194 |
stats.getOp++; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
195 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
196 |
// use cache: |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
197 |
if (tail != 0) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
198 |
final byte[] array = arrays[--tail]; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
199 |
arrays[tail] = null; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
200 |
return array; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
201 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
202 |
if (DO_STATS) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
203 |
stats.createOp++; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
204 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
205 |
return createArray(arraySize, clean); |
34417 | 206 |
} |
207 |
||
40421
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
208 |
void putArray(final byte[] array) |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
209 |
{ |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
210 |
if (DO_CHECKS && (array.length != arraySize)) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
211 |
logInfo(getLogPrefix(clean) + "ByteArrayCache: " |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
212 |
+ "bad length = " + array.length); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
213 |
return; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
214 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
215 |
if (DO_STATS) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
216 |
stats.returnOp++; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
217 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
218 |
// fill cache: |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
219 |
if (arrays.length > tail) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
220 |
arrays[tail++] = array; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
221 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
222 |
if (DO_STATS) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
223 |
stats.updateMaxSize(tail); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
224 |
} |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
225 |
} else if (DO_CHECKS) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
226 |
logInfo(getLogPrefix(clean) + "ByteArrayCache: " |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
227 |
+ "array capacity exceeded !"); |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
228 |
} |
34417 | 229 |
} |
230 |
} |
|
231 |
||
40421
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
232 |
static byte[] createArray(final int length, final boolean clean) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
233 |
if (clean) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
234 |
return new byte[length]; |
34417 | 235 |
} |
47126 | 236 |
// use JDK9 Unsafe.allocateUninitializedArray(class, length): |
237 |
return (byte[]) OffHeapArray.UNSAFE.allocateUninitializedArray(byte.class, length); |
|
34417 | 238 |
} |
239 |
||
240 |
static void fill(final byte[] array, final int fromIndex, |
|
241 |
final int toIndex, final byte value) |
|
242 |
{ |
|
243 |
// clear array data: |
|
40421
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
244 |
Arrays.fill(array, fromIndex, toIndex, value); |
39519
21bfc4452441
8159093: Fix coding conventions in Marlin renderer
lbourges
parents:
36458
diff
changeset
|
245 |
if (DO_CHECKS) { |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34816
diff
changeset
|
246 |
check(array, fromIndex, toIndex, value); |
34417 | 247 |
} |
248 |
} |
|
249 |
||
250 |
static void check(final byte[] array, final int fromIndex, |
|
251 |
final int toIndex, final byte value) |
|
252 |
{ |
|
39519
21bfc4452441
8159093: Fix coding conventions in Marlin renderer
lbourges
parents:
36458
diff
changeset
|
253 |
if (DO_CHECKS) { |
34417 | 254 |
// check zero on full array: |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34816
diff
changeset
|
255 |
for (int i = 0; i < array.length; i++) { |
34417 | 256 |
if (array[i] != value) { |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34816
diff
changeset
|
257 |
logException("Invalid value at: " + i + " = " + array[i] |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34816
diff
changeset
|
258 |
+ " from: " + fromIndex + " to: " + toIndex + "\n" |
34417 | 259 |
+ Arrays.toString(array), new Throwable()); |
260 |
||
261 |
// ensure array is correctly filled: |
|
262 |
Arrays.fill(array, value); |
|
263 |
||
264 |
return; |
|
265 |
} |
|
266 |
} |
|
267 |
} |
|
268 |
} |
|
40421
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
269 |
|
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
270 |
static String getLogPrefix(final boolean clean) { |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
271 |
return (clean) ? "Clean" : "Dirty"; |
d5ee65e2b0fb
8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents:
39519
diff
changeset
|
272 |
} |
34417 | 273 |
} |