< prev index next >

src/java.base/share/classes/java/lang/StringConcatHelper.java

Print this page
rev 58565 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: duke
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com


  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  */
  25 
  26 package java.lang;
  27 
  28 import jdk.internal.misc.Unsafe;
  29 import jdk.internal.vm.annotation.ForceInline;
  30 




  31 /**
  32  * Helper for string concatenation. These methods are mostly looked up with private lookups
  33  * from {@link java.lang.invoke.StringConcatFactory}, and used in {@link java.lang.invoke.MethodHandle}
  34  * combinators there.
  35  */
  36 final class StringConcatHelper {
  37 
  38     private StringConcatHelper() {
  39         // no instantiation
  40     }
  41 
  42     /**
  43      * Check for overflow, throw exception on overflow.
  44      *
  45      * @param lengthCoder String length with coder packed into higher bits
  46      *                    the upper word.
  47      * @return            the given parameter value, if valid
  48      */
  49     private static long checkOverflow(long lengthCoder) {
  50         if ((int)lengthCoder >= 0) {


 449      * Allocates an uninitialized byte array based on the length and coder information
 450      * in indexCoder
 451      * @param indexCoder
 452      * @return the newly allocated byte array
 453      */
 454     @ForceInline
 455     static byte[] newArray(long indexCoder) {
 456         byte coder = (byte)(indexCoder >> 32);
 457         int index = (int)indexCoder;
 458         return (byte[]) UNSAFE.allocateUninitializedArray(byte.class, index << coder);
 459     }
 460 
 461     /**
 462      * Provides the initial coder for the String.
 463      * @return initial coder, adjusted into the upper half
 464      */
 465     static long initialCoder() {
 466         return String.COMPACT_STRINGS ? LATIN1 : UTF16;
 467     }
 468 









 469 }


  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  */
  25 
  26 package java.lang;
  27 
  28 import jdk.internal.misc.Unsafe;
  29 import jdk.internal.vm.annotation.ForceInline;
  30 
  31 import java.lang.invoke.MethodHandle;
  32 import java.lang.invoke.MethodHandles;
  33 import java.lang.invoke.MethodType;
  34 
  35 /**
  36  * Helper for string concatenation. These methods are mostly looked up with private lookups
  37  * from {@link java.lang.invoke.StringConcatFactory}, and used in {@link java.lang.invoke.MethodHandle}
  38  * combinators there.
  39  */
  40 final class StringConcatHelper {
  41 
  42     private StringConcatHelper() {
  43         // no instantiation
  44     }
  45 
  46     /**
  47      * Check for overflow, throw exception on overflow.
  48      *
  49      * @param lengthCoder String length with coder packed into higher bits
  50      *                    the upper word.
  51      * @return            the given parameter value, if valid
  52      */
  53     private static long checkOverflow(long lengthCoder) {
  54         if ((int)lengthCoder >= 0) {


 453      * Allocates an uninitialized byte array based on the length and coder information
 454      * in indexCoder
 455      * @param indexCoder
 456      * @return the newly allocated byte array
 457      */
 458     @ForceInline
 459     static byte[] newArray(long indexCoder) {
 460         byte coder = (byte)(indexCoder >> 32);
 461         int index = (int)indexCoder;
 462         return (byte[]) UNSAFE.allocateUninitializedArray(byte.class, index << coder);
 463     }
 464 
 465     /**
 466      * Provides the initial coder for the String.
 467      * @return initial coder, adjusted into the upper half
 468      */
 469     static long initialCoder() {
 470         return String.COMPACT_STRINGS ? LATIN1 : UTF16;
 471     }
 472 
 473     static MethodHandle lookupStatic(String name, MethodType methodType) {
 474         try {
 475             return MethodHandles.lookup().findStatic(StringConcatHelper.class, name, methodType);
 476         } catch (NoSuchMethodException|IllegalAccessException e) {
 477             throw new AssertionError(e);
 478         }
 479     }
 480 
 481 
 482 }
< prev index next >