Move runtime.jvm sources to stdlib/jvm/runtime

Update path in kotlin-runtime
Update path in kotlin-mock-runtime-for-tests
This commit is contained in:
Ilya Gorbunov
2018-01-31 07:04:43 +03:00
committed by Stanislav Erokhin
parent 00b23a0fe9
commit c796e5338b
67 changed files with 143 additions and 336 deletions
@@ -1,26 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin;
public class TypeCastException extends ClassCastException {
public TypeCastException() {
}
public TypeCastException(String message) {
super(message);
}
}
@@ -1,35 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.jvm;
public class KotlinReflectionNotSupportedError extends Error {
public KotlinReflectionNotSupportedError() {
super("Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath");
}
public KotlinReflectionNotSupportedError(String message) {
super(message);
}
public KotlinReflectionNotSupportedError(String message, Throwable cause) {
super(message, cause);
}
public KotlinReflectionNotSupportedError(Throwable cause) {
super(cause);
}
}
@@ -1,87 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.jvm.internal;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
public class CollectionToArray {
// Based on the implementation from AbstractCollection
@SuppressWarnings("SSBasedInspection")
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
public static Object[] toArray(Collection<?> collection) {
int size = collection.size();
if (size == 0) return EMPTY_OBJECT_ARRAY;
Object[] r = new Object[size];
Iterator<?> it = collection.iterator();
for (int i = 0; i < size; i++) {
if (!it.hasNext()) {
// fewer elements than expected
return Arrays.copyOf(r, i);
}
r[i] = it.next();
}
return it.hasNext() ? finishToArray(r, it) : r;
}
public static <T, E> T[] toArray(Collection<E> collection, T[] a) {
// Estimate size of array; be prepared to see more or fewer elements
int size = collection.size();
T[] r = a.length >= size ? a :
(T[])java.lang.reflect.Array
.newInstance(a.getClass().getComponentType(), size);
Iterator<E> it = collection.iterator();
for (int i = 0; i < r.length; i++) {
if (! it.hasNext()) { // fewer elements than expected
if (a != r)
return Arrays.copyOf(r, i);
r[i] = null; // null-terminate
return r;
}
r[i] = (T)it.next();
}
return it.hasNext() ? finishToArray(r, it) : r;
}
private static <T> T[] finishToArray(T[] r, Iterator<?> it) {
int i = r.length;
while (it.hasNext()) {
int cap = r.length;
if (i == cap) {
int newCap = ((cap / 2) + 1) * 3;
if (newCap <= cap) { // integer overflow
if (cap == Integer.MAX_VALUE)
throw new OutOfMemoryError
("Required array size too large");
newCap = Integer.MAX_VALUE;
}
r = Arrays.copyOf(r, newCap);
}
r[i++] = (T)it.next();
}
// trim if overallocated
return (i == r.length) ? r : Arrays.copyOf(r, i);
}
private CollectionToArray() {
}
}
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.jvm.internal.markers;
public interface KMappedMarker {
}
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.jvm.internal.markers;
public interface KMutableIterable extends KMappedMarker {
}
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.jvm.internal.markers;
public interface KMutableIterator extends KMappedMarker {
}
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.jvm.internal.markers;
public interface KMutableList extends KMutableCollection {
}
@@ -1,22 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.jvm.internal.markers;
public interface KMutableMap extends KMappedMarker {
interface Entry extends KMappedMarker {
}
}
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.jvm.internal.markers;
public interface KMutableSet extends KMutableCollection {
}
+1 -7
View File
@@ -21,13 +21,7 @@ sourceSets {
builtins {
java {
srcDir "${rootDir}/core/builtins/src"
srcDir "${rootDir}/core/runtime.jvm/src"
exclude 'org/jetbrains/annotations/**'
}
kotlin {
srcDir "${rootDir}/core/builtins/src"
srcDir "${rootDir}/core/runtime.jvm/src"
exclude 'org/jetbrains/annotations/**'
srcDir "jvm/runtime"
}
}
main {
@@ -14,7 +14,10 @@
* limitations under the License.
*/
package kotlin.jvm.internal.markers;
package kotlin
public interface KMutableCollection extends KMutableIterable {
public open class KotlinNullPointerException : NullPointerException {
constructor()
constructor(message: String?) : super(message)
}
@@ -14,13 +14,14 @@
* limitations under the License.
*/
package kotlin;
package kotlin
public class KotlinNullPointerException extends NullPointerException {
public KotlinNullPointerException() {
}
public open class NoWhenBranchMatchedException : RuntimeException {
constructor()
public KotlinNullPointerException(String message) {
super(message);
}
constructor(message: String?) : super(message)
constructor(message: String?, cause: Throwable?) : super(message, cause)
constructor(cause: Throwable?) : super(cause)
}
@@ -14,7 +14,10 @@
* limitations under the License.
*/
package kotlin.jvm.internal.markers;
package kotlin
public interface KMutableListIterator extends KMutableIterator {
public open class TypeCastException : ClassCastException {
constructor()
constructor(message: String?) : super(message)
}
@@ -14,21 +14,16 @@
* limitations under the License.
*/
package kotlin;
package kotlin.jvm
public class NoWhenBranchMatchedException extends RuntimeException {
public NoWhenBranchMatchedException() {
}
import java.lang.Error
public NoWhenBranchMatchedException(String message) {
super(message);
}
public open class KotlinReflectionNotSupportedError : Error {
constructor() : super("Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath")
public NoWhenBranchMatchedException(String message, Throwable cause) {
super(message, cause);
}
constructor(message: String?) : super(message)
public NoWhenBranchMatchedException(Throwable cause) {
super(cause);
}
constructor(message: String?, cause: Throwable?) : super(message, cause)
constructor(cause: Throwable?) : super(cause)
}
@@ -0,0 +1,81 @@
/*
* Copyright 2000-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("CollectionToArray")
package kotlin.jvm.internal
import java.lang.reflect.Array as JavaArray
import java.lang.NullPointerException as JavaNPE
import java.util.Arrays
private val EMPTY = emptyArray<Any?>() // shared empty array
private const val MAX_SIZE = Int.MAX_VALUE - 2 // empirically maximal array size that can be allocated without exceeding VM limits
@JvmName("toArray")
fun collectionToArray(collection: Collection<*>): Array<Any?> =
toArrayImpl(
collection,
empty = { EMPTY },
alloc = { size -> arrayOfNulls<Any?>(size) },
trim = { result, size -> Arrays.copyOf(result, size) }
)
// Note: Array<Any?> here can have any reference array JVM type at run time
@JvmName("toArray")
fun collectionToArray(collection: Collection<*>, a: Array<Any?>?): Array<Any?> {
// Collection.toArray contract requires that NullPointerException is thrown when array is null
if (a == null) throw JavaNPE()
return toArrayImpl(
collection,
empty = {
if (a.size > 0) a[0] = null
a
},
alloc = { size ->
@Suppress("UNCHECKED_CAST")
if (size <= a.size) a else JavaArray.newInstance(a.javaClass.componentType, size) as Array<Any?>
},
trim = { result, size ->
if (result === a) {
a[size] = null
a
} else
Arrays.copyOf(result, size)
}
)
}
private inline fun toArrayImpl(
collection: Collection<*>,
empty: () -> Array<Any?>,
alloc: (Int) -> Array<Any?>,
trim: (Array<Any?>, Int) -> Array<Any?>
): Array<Any?> {
val size = collection.size
if (size == 0) return empty() // quick path on zero size
val iter = collection.iterator() // allocate iterator for non-empty collection
if (!iter.hasNext()) return empty() // size was > 0, but no actual elements
var result = alloc(size) // use size as a guess to allocate result array
var i = 0
// invariant: iter.hasNext is true && i < result.size
while (true) {
result[i++] = iter.next()
if (i >= result.size) {
if (!iter.hasNext()) return result // perfect match of array size
// array size was too small -- grow array (invariant: i == result.size > 0 here)
// now grow at a factor of 1.5 (we expect this to be extremely rare, but still use fast code)
// note that corner case here is when i == 1 (should get newSize == 2)
var newSize = (i * 3 + 1) ushr 1
if (newSize <= i) { // detect overflow in the above line
if (i >= MAX_SIZE) throw OutOfMemoryError() // exceeded max array that VM can allocate
newSize = MAX_SIZE // try max array size that VM can allocate
}
result = Arrays.copyOf(result, newSize)
} else {
if (!iter.hasNext()) return trim(result, i) // ended too early (allocated array too big)
}
}
}
@@ -0,0 +1,24 @@
/*
* Copyright 2000-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.
*/
package kotlin.jvm.internal.markers
interface KMappedMarker
interface KMutableIterable : KMappedMarker
interface KMutableCollection : KMutableIterable
interface KMutableList : KMutableCollection
interface KMutableIterator : KMappedMarker
interface KMutableListIterator : KMutableIterator
interface KMutableMap : KMappedMarker {
interface Entry : KMappedMarker
}
interface KMutableSet : KMutableCollection
@@ -228,12 +228,12 @@ internal fun <T> List<T>.optimizeReadOnlyList() = when (size) {
@JvmVersion
@kotlin.internal.InlineOnly
internal inline fun copyToArrayImpl(collection: Collection<*>): Array<Any?> =
kotlin.jvm.internal.CollectionToArray.toArray(collection)
kotlin.jvm.internal.collectionToArray(collection)
@JvmVersion
@kotlin.internal.InlineOnly
internal inline fun <T> copyToArrayImpl(collection: Collection<*>, array: Array<T>): Array<T> =
kotlin.jvm.internal.CollectionToArray.toArray(collection, array)
kotlin.jvm.internal.collectionToArray(collection, array as Array<Any?>) as Array<T>
// copies typed varargs array to array of objects
@JvmVersion
@@ -445,9 +445,9 @@ public final class kotlin/jvm/internal/ClassReference : kotlin/jvm/internal/Clas
public fun toString ()Ljava/lang/String;
}
public class kotlin/jvm/internal/CollectionToArray {
public static fun toArray (Ljava/util/Collection;)[Ljava/lang/Object;
public static fun toArray (Ljava/util/Collection;[Ljava/lang/Object;)[Ljava/lang/Object;
public final class kotlin/jvm/internal/CollectionToArray {
public static final fun toArray (Ljava/util/Collection;)[Ljava/lang/Object;
public static final fun toArray (Ljava/util/Collection;[Ljava/lang/Object;)[Ljava/lang/Object;
}
public final class kotlin/jvm/internal/DoubleCompanionObject {
@@ -2495,9 +2495,9 @@ public final class kotlin/jvm/internal/ClassReference : kotlin/jvm/internal/Clas
public fun toString ()Ljava/lang/String;
}
public class kotlin/jvm/internal/CollectionToArray {
public static fun toArray (Ljava/util/Collection;)[Ljava/lang/Object;
public static fun toArray (Ljava/util/Collection;[Ljava/lang/Object;)[Ljava/lang/Object;
public final class kotlin/jvm/internal/CollectionToArray {
public static final fun toArray (Ljava/util/Collection;)[Ljava/lang/Object;
public static final fun toArray (Ljava/util/Collection;[Ljava/lang/Object;)[Ljava/lang/Object;
}
public final class kotlin/jvm/internal/DoubleCompanionObject {
+1 -5
View File
@@ -15,11 +15,7 @@ sourceSets {
if(!System.properties.'idea.active') {
java {
srcDir "${rootDir}/core/builtins/src"
srcDir "${rootDir}/core/runtime.jvm/src"
exclude 'org/jetbrains/annotations/**'
}
kotlin {
exclude 'org/jetbrains/annotations/**'
srcDir "${rootDir}/libraries/stdlib/jvm/runtime"
}
}
}
+2 -22
View File
@@ -15,24 +15,16 @@ sourceSets {
"main" {
java.apply {
srcDir(File(buildDir, "src"))
// srcDir(File(rootDir, "core", "runtime.jvm", "src"))
// .include("kotlin/TypeAliases.kt",
// "kotlin/text/TypeAliases.kt")
// srcDir(File(rootDir, "libraries", "stdlib", "src"))
// .include("kotlin/collections/TypeAliases.kt",
// "kotlin/jvm/JvmVersion.kt",
// "kotlin/util/Standard.kt",
// "kotlin/internal/Annotations.kt")
}
}
"test" {}
}
val copySources by task<Copy> {
from(File(rootDir, "core", "runtime.jvm", "src"))
from(project(":kotlin-stdlib").projectDir.resolve("jvm/runtime"))
.include("kotlin/TypeAliases.kt",
"kotlin/text/TypeAliases.kt")
from(File(rootDir, "libraries", "stdlib", "src"))
from(project(":kotlin-stdlib").projectDir.resolve("src"))
.include("kotlin/collections/TypeAliases.kt",
"kotlin/jvm/JvmVersion.kt",
"kotlin/util/Standard.kt",
@@ -57,18 +49,6 @@ tasks.withType<KotlinCompile> {
val jar = runtimeJar {
dependsOn(":core:builtins:serialize")
from(fileTree("${rootProject.extra["distDir"]}/builtins")) { include("kotlin/**") }
// dependsOn(":kotlin-stdlib:classes")
// project(":kotlin-stdlib").let { p ->
// p.pluginManager.withPlugin("java") {
// from(p.the<JavaPluginConvention>().sourceSets.getByName("main").output) {
// include("kotlin/**/TypeAliases*.class",
// "kotlin/jvm/JvmVersion.class",
// "kotlin/StandardKt*.class",
// "kotlin/NotImplementedError*.class",
// "kotlin/internal/*.class")
// }
// }
// }
}
val distDir: String by rootProject.extra