jdk/src/java.desktop/share/classes/sun/java2d/marlin/FloatArrayCache.java
changeset 47126 188ef162f019
parent 40421 d5ee65e2b0fb
equal deleted inserted replaced
45093:c42dc7b58b4d 47126:188ef162f019
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    20  *
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    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
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
       
    25 
    25 package sun.java2d.marlin;
    26 package sun.java2d.marlin;
    26 
    27 
    27 import static sun.java2d.marlin.ArrayCacheConst.ARRAY_SIZES;
    28 import static sun.java2d.marlin.ArrayCacheConst.ARRAY_SIZES;
    28 import static sun.java2d.marlin.ArrayCacheConst.BUCKETS;
    29 import static sun.java2d.marlin.ArrayCacheConst.BUCKETS;
    29 import static sun.java2d.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
    30 import static sun.java2d.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
    35 
    36 
    36 import sun.java2d.marlin.ArrayCacheConst.BucketStats;
    37 import sun.java2d.marlin.ArrayCacheConst.BucketStats;
    37 import sun.java2d.marlin.ArrayCacheConst.CacheStats;
    38 import sun.java2d.marlin.ArrayCacheConst.CacheStats;
    38 
    39 
    39 /*
    40 /*
    40  * Note that the [BYTE/INT/FLOAT]ArrayCache files are nearly identical except
    41  * Note that the [BYTE/INT/FLOAT/DOUBLE]ArrayCache files are nearly identical except
    41  * for a few type and name differences. Typically, the [BYTE]ArrayCache.java file
    42  * for a few type and name differences. Typically, the [BYTE]ArrayCache.java file
    42  * is edited manually and then [INT]ArrayCache.java and [FLOAT]ArrayCache.java
    43  * is edited manually and then [INT/FLOAT/DOUBLE]ArrayCache.java
    43  * files are generated with the following command lines:
    44  * files are generated with the following command lines:
    44  */
    45  */
    45 // % sed -e 's/(b\yte)[ ]*//g' -e 's/b\yte/int/g' -e 's/B\yte/Int/g' < B\yteArrayCache.java > IntArrayCache.java
    46 // % sed -e 's/(b\yte)[ ]*//g' -e 's/b\yte/int/g' -e 's/B\yte/Int/g' < B\yteArrayCache.java > IntArrayCache.java
    46 // % sed -e 's/(b\yte)[ ]*/(float) /g' -e 's/b\yte/float/g' -e 's/B\yte/Float/g' < B\yteArrayCache.java > FloatArrayCache.java
    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
    47 
    49 
    48 final class FloatArrayCache implements MarlinConst {
    50 final class FloatArrayCache implements MarlinConst {
    49 
    51 
    50     final boolean clean;
    52     final boolean clean;
    51     private final int bucketCapacity;
    53     private final int bucketCapacity;
   157                         final int toIndex)
   159                         final int toIndex)
   158         {
   160         {
   159             if (array.length <= MAX_ARRAY_SIZE) {
   161             if (array.length <= MAX_ARRAY_SIZE) {
   160                 if ((clean || DO_CLEAN_DIRTY) && (toIndex != 0)) {
   162                 if ((clean || DO_CLEAN_DIRTY) && (toIndex != 0)) {
   161                     // clean-up array of dirty part[fromIndex; toIndex[
   163                     // clean-up array of dirty part[fromIndex; toIndex[
   162                     fill(array, fromIndex, toIndex, (float) 0);
   164                     fill(array, fromIndex, toIndex, 0.0f);
   163                 }
   165                 }
   164                 // ensure to never store initial arrays in cache:
   166                 // ensure to never store initial arrays in cache:
   165                 if (array != initial) {
   167                 if (array != initial) {
   166                     cache.getCacheBucket(array.length).putArray(array);
   168                     cache.getCacheBucket(array.length).putArray(array);
   167                 }
   169                 }
   229 
   231 
   230     static float[] createArray(final int length, final boolean clean) {
   232     static float[] createArray(final int length, final boolean clean) {
   231         if (clean) {
   233         if (clean) {
   232             return new float[length];
   234             return new float[length];
   233         }
   235         }
   234        // use JDK9 Unsafe.allocateUninitializedArray(class, length):
   236         // use JDK9 Unsafe.allocateUninitializedArray(class, length):
   235        return (float[]) OffHeapArray.UNSAFE.allocateUninitializedArray(float.class, length);
   237         return (float[]) OffHeapArray.UNSAFE.allocateUninitializedArray(float.class, length);
   236     }
   238     }
   237 
   239 
   238     static void fill(final float[] array, final int fromIndex,
   240     static void fill(final float[] array, final int fromIndex,
   239                      final int toIndex, final float value)
   241                      final int toIndex, final float value)
   240     {
   242     {