Add our own primitive boxing methods to stdlib

These methods are very thin wrappers around primitive wrapper classes
constructors.
They are used by coroutines code which returns primitives and this way
HotSpot is able to throw the allocations away completely.
 #KT-26591 Fixed
This commit is contained in:
Ilmir Usmanov
2018-09-12 15:34:15 +03:00
parent 792c5f8b3f
commit 273889d1a9
2 changed files with 59 additions and 0 deletions
@@ -0,0 +1,48 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
@file:JvmName("Boxing")
@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
package kotlin.coroutines.jvm.internal
/*
* Box primitive to Java wrapper class by allocating the wrapper object.
*
* This allows HotSpot JIT to eliminate allocations completely in coroutines code with primitives.
*/
@SinceKotlin("1.3")
@PublishedApi
internal fun boxBoolean(primitive: Boolean): java.lang.Boolean = java.lang.Boolean.valueOf(primitive) as java.lang.Boolean
@SinceKotlin("1.3")
@PublishedApi
internal fun boxByte(primitive: Byte): java.lang.Byte = java.lang.Byte.valueOf(primitive) as java.lang.Byte
@SinceKotlin("1.3")
@PublishedApi
internal fun boxShort(primitive: Short): java.lang.Short = java.lang.Short(primitive)
@SinceKotlin("1.3")
@PublishedApi
internal fun boxInt(primitive: Int): java.lang.Integer = java.lang.Integer(primitive)
@SinceKotlin("1.3")
@PublishedApi
internal fun boxLong(primitive: Long): java.lang.Long = java.lang.Long(primitive)
@SinceKotlin("1.3")
@PublishedApi
internal fun boxFloat(primitive: Float): java.lang.Float = java.lang.Float(primitive)
@SinceKotlin("1.3")
@PublishedApi
internal fun boxDouble(primitive: Double): java.lang.Double = java.lang.Double(primitive)
@SinceKotlin("1.3")
@PublishedApi
internal fun boxChar(primitive: Char): java.lang.Character = java.lang.Character(primitive)
@@ -2852,6 +2852,17 @@ public final class kotlin/coroutines/intrinsics/IntrinsicsKt {
public static final fun intercepted (Lkotlin/coroutines/Continuation;)Lkotlin/coroutines/Continuation;
}
public final class kotlin/coroutines/jvm/internal/Boxing {
public static final fun boxBoolean (Z)Ljava/lang/Boolean;
public static final fun boxByte (B)Ljava/lang/Byte;
public static final fun boxChar (C)Ljava/lang/Character;
public static final fun boxDouble (D)Ljava/lang/Double;
public static final fun boxFloat (F)Ljava/lang/Float;
public static final fun boxInt (I)Ljava/lang/Integer;
public static final fun boxLong (J)Ljava/lang/Long;
public static final fun boxShort (S)Ljava/lang/Short;
}
public abstract interface class kotlin/coroutines/jvm/internal/CoroutineStackFrame {
public abstract fun getCallerFrame ()Lkotlin/coroutines/jvm/internal/CoroutineStackFrame;
public abstract fun getStackTraceElement ()Ljava/lang/StackTraceElement;