< prev index next >

src/java.desktop/share/classes/sun/java2d/marlin/IntArrayCache.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


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

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


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