< prev index next >

src/java.desktop/share/classes/sun/java2d/marlin/FloatArrayCache.java

Print this page


   1 /*
   2  * Copyright (c) 2015, 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


 110         // clean-up array of dirty part[fromIndex; toIndex[
 111         fill(array, fromIndex, toIndex, 0f);
 112 
 113         // fill cache:
 114         floatArrays.addLast(array);
 115     }
 116 
 117     static void fill(final float[] array, final int fromIndex,
 118                      final int toIndex, final float value)
 119     {
 120         // clear array data:
 121         /*
 122          * Arrays.fill is faster than System.arraycopy(empty array)
 123          * or Unsafe.setMemory(byte 0)
 124          */
 125         if (toIndex != 0) {
 126             Arrays.fill(array, fromIndex, toIndex, value);
 127         }
 128 
 129         if (doChecks) {
 130             check(array, 0, array.length, value);
 131         }
 132     }
 133 
 134     static void check(final float[] array, final int fromIndex,
 135                       final int toIndex, final float value)
 136     {
 137         if (doChecks) {
 138             // check zero on full array:
 139             for (int i = fromIndex; i < toIndex; i++) {
 140                 if (array[i] != value) {
 141                     logException("Invalid array value at " + i + "\n"

 142                             + Arrays.toString(array), new Throwable());
 143 
 144                     // ensure array is correctly filled:
 145                     Arrays.fill(array, value);
 146 
 147                     return;
 148                 }
 149             }
 150         }
 151     }
 152 }
   1 /*
   2  * Copyright (c) 2015, 2016, 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


 110         // clean-up array of dirty part[fromIndex; toIndex[
 111         fill(array, fromIndex, toIndex, 0f);
 112 
 113         // fill cache:
 114         floatArrays.addLast(array);
 115     }
 116 
 117     static void fill(final float[] array, final int fromIndex,
 118                      final int toIndex, final float value)
 119     {
 120         // clear array data:
 121         /*
 122          * Arrays.fill is faster than System.arraycopy(empty array)
 123          * or Unsafe.setMemory(byte 0)
 124          */
 125         if (toIndex != 0) {
 126             Arrays.fill(array, fromIndex, toIndex, value);
 127         }
 128 
 129         if (doChecks) {
 130             check(array, fromIndex, toIndex, value);
 131         }
 132     }
 133 
 134     static void check(final float[] array, final int fromIndex,
 135                       final int toIndex, final float value)
 136     {
 137         if (doChecks) {
 138             // check zero on full array:
 139             for (int i = 0; i < array.length; i++) {
 140                 if (array[i] != value) {
 141                     logException("Invalid value at: " + i + " = " + array[i]
 142                             + " from: " + fromIndex + " to: " + toIndex + "\n"
 143                             + Arrays.toString(array), new Throwable());
 144 
 145                     // ensure array is correctly filled:
 146                     Arrays.fill(array, value);
 147 
 148                     return;
 149                 }
 150             }
 151         }
 152     }
 153 }
< prev index next >