make/jdk/src/classes/build/tools/generatebreakiteratordata/SupplementaryCharacterData.java
author vlivanov
Thu, 18 Jan 2018 02:25:18 +0300
changeset 48596 860326263d1f
parent 47216 71c04702a3d5
permissions -rw-r--r--
8194963: SystemDictionary::link_method_handle_constant() can't link MethodHandle.invoke()/invokeExact() Reviewed-by: kvn, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21805
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package build.tools.generatebreakiteratordata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
final class SupplementaryCharacterData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
     * Default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    private static final byte DEFAULT_VALUE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    private byte defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * A array which has a unicode code point(0x010000-0x10FFFF) as the upper
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * 3 bytes and a value as the remaining one byte in each data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private int[] dataTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * Counter to keep the number of data in tempTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private int dataCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Temporary data table used until dataTable is generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private long[] tempTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Initila tempTable size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static final int INITIAL_TABLE_SIZE = 150;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * The number of entries to be appended when tempTable becomes full
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static final int ADDITIONAL_TABLE_SIZE = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Upper limit, used as a sentinel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static final int UPPER_LIMIT = Character.MAX_CODE_POINT + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Mask for supplementary code points(0x010000-0x10FFFF)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static final int CODEPOINT_MASK = 0x1FFFFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public SupplementaryCharacterData(byte value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        defaultValue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        dataCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Appends the given data to tempTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public void appendElement(int start, int end, byte value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (tempTable == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            tempTable = new long[INITIAL_TABLE_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if (dataCount == tempTable.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            long[] tempTempTable = new long[dataCount + ADDITIONAL_TABLE_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            System.arraycopy(tempTable, 0, tempTempTable, 0, dataCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            tempTable = tempTempTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        tempTable[dataCount++] = ((((long)start<<24) + end)<<8) + value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Returns the data table
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public int[] getArray() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return dataTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Creates dataTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public void complete() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        dataTable = generateTable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Generates a table from the given data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private int[] generateTable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        /* If tempTable is empty, put two data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (dataCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            int[] tmpArray = new int[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            tmpArray[0] = composeEntry(0, DEFAULT_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            tmpArray[1] = composeEntry(UPPER_LIMIT, DEFAULT_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            tempTable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            return tmpArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        Arrays.sort(tempTable, 0, dataCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        int[] newTempTable = new int[dataCount*2 + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        int old_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        int new_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        int loop_count = dataCount - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        long data = tempTable[old_index];
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   131
        int start = (int)(data>>32) & CODEPOINT_MASK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        int end   = (int)(data>>8) & CODEPOINT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
         * Add an entry if the first start code point in tempTable is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         * the minimum supplementary code point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (start != Character.MIN_SUPPLEMENTARY_CODE_POINT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            newTempTable[new_index++] = composeEntry(Character.MIN_SUPPLEMENTARY_CODE_POINT, defaultValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        newTempTable[new_index++] = composeEntry(start, (int)data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        for (int i = 0; i < loop_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            data = tempTable[++old_index];
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   145
            int nextStart = (int)(data>>32) & CODEPOINT_MASK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
             * If the previous end code point is not equal to the previous start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
             * code point and is not consecutive with the next start code point,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
             * insert a filler entry before an entry for the next start code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
             * point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            if (end != start && end != nextStart-1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                newTempTable[new_index++] = composeEntry(end + 1, defaultValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            newTempTable[new_index++] = composeEntry(nextStart, (int)data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            start = nextStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            end = (int)(data>>8) & CODEPOINT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        newTempTable[new_index++] = composeEntry(++end, defaultValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        /* Add an entry for a sentinel if necessary. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (end < UPPER_LIMIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            newTempTable[new_index++] = composeEntry(UPPER_LIMIT, defaultValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        /* Copy data to dataTable. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        dataTable = new int[new_index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        System.arraycopy(newTempTable, 0, dataTable, 0, new_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        tempTable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return dataTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Composes an entry with the given supplementary code point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * (0x010000-0x10FFFF) for the upper 3 bytes and the given value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * remaining one byte.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private int composeEntry(int codePoint, int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return (codePoint<<8) | (value&0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
}