IJPL-136 update amazon ion library (64MB cache is used now, not possible to customize without fork or reflection)

GitOrigin-RevId: 3e9bf372813b1d8f12bd4729f02f02006f05f261
This commit is contained in:
Vladimir Krivosheev
2023-12-16 09:49:00 +01:00
committed by intellij-monorepo-bot
parent 28f2503046
commit 5473d915f7
6 changed files with 11 additions and 140 deletions

View File

@@ -1,9 +1,9 @@
<component name="libraryTable">
<library name="ion" type="repository">
<properties include-transitive-deps="false" maven-id="org.jetbrains.intellij.deps:ion-java:1.8.2-4">
<properties maven-id="com.amazon.ion:ion-java:1.11.0">
<verification>
<artifact url="file://$MAVEN_REPOSITORY$/org/jetbrains/intellij/deps/ion-java/1.8.2-4/ion-java-1.8.2-4.jar">
<sha256sum>d7e6ae22a82bf0c99bb3cfbf5090f112d94acf6bc5353c90414428f4b9b854d9</sha256sum>
<artifact url="file://$MAVEN_REPOSITORY$/com/amazon/ion/ion-java/1.11.0/ion-java-1.11.0.jar">
<sha256sum>edfe41ebf7e3c460ab9127578a92874126e93b5732eab7115ceeb568031ee348</sha256sum>
</artifact>
</verification>
</properties>
@@ -11,11 +11,11 @@
<root url="file://$PROJECT_DIR$/lib/annotations/ion" />
</ANNOTATIONS>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/intellij/deps/ion-java/1.8.2-4/ion-java-1.8.2-4.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/amazon/ion/ion-java/1.11.0/ion-java-1.11.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/intellij/deps/ion-java/1.8.2-4/ion-java-1.8.2-4-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/amazon/ion/ion-java/1.11.0/ion-java-1.11.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@@ -187,7 +187,7 @@ internal suspend fun createPlatformLayout(addPlatformCoverage: Boolean,
"intellij.platform.util.rt",
"intellij.platform.util.trove",
), productLayout = productLayout, layout = layout)
layout.withProjectLibrary(libraryName = "ion", jarName = UTIL_RT_JAR)
layout.withProjectLibrary(libraryName = "ion", jarName = UTIL_8_JAR)
// skiko-runtime needed for Compose
layout.withModuleLibrary(

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:Suppress("ReplaceGetOrSet")
package com.intellij.serialization
@@ -196,7 +196,7 @@ private data class ReadContextImpl(override val reader: ValueReader,
internal val binaryWriterBuilder by lazy {
val binaryWriterBuilder = _Private_IonManagedBinaryWriterBuilder
.create(PooledBlockAllocatorProvider())
.create(_Private_IonManagedBinaryWriterBuilder.AllocatorMode.POOLED)
.withPaddedLengthPreallocation(0)
.withLocalSymbolTableAppendEnabled()
.withStreamCopyOptimization(true)

View File

@@ -1,102 +0,0 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.serialization
import com.amazon.ion.impl.bin.Block
import com.amazon.ion.impl.bin.BlockAllocator
import com.amazon.ion.impl.bin.BlockAllocatorProvider
import org.jetbrains.annotations.TestOnly
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentLinkedQueue
import java.util.concurrent.atomic.AtomicInteger
internal class PooledBlockAllocatorProvider : BlockAllocatorProvider() {
companion object {
// 512 KB
internal const val POOL_THRESHOLD = 512 * 1024
}
private val allocators = ConcurrentHashMap<Int, Queue<PooledBlockAllocator>>()
private inner class PooledBlockAllocator(private val blockSize: Int) : BlockAllocator() {
private val freeBlocks = ArrayList<Block>()
private val blockCounter = AtomicInteger()
val byteSize: Int
get() = blockCounter.get() * blockSize
override fun allocateBlock(): Block {
val lastIndex = freeBlocks.lastIndex
if (lastIndex != -1) {
return freeBlocks.removeAt(lastIndex)
}
blockCounter.incrementAndGet()
return object : Block(ByteArray(blockSize)) {
override fun close() {
reset()
freeBlocks.add(this)
}
}
}
override fun getBlockSize() = blockSize
override fun close() {
if ((blockSize * freeBlocks.size) > POOL_THRESHOLD) {
// help GC - nullize
freeBlocks.clear()
blockCounter.set(0)
return
}
allocators.getOrPut(blockSize, ::ConcurrentLinkedQueue).add(this)
removeExcess()
}
}
@get:TestOnly
val byteSize: Int
get() {
var totalByteSize = 0
for (allocator in allocators.values.flatten()) {
totalByteSize += allocator.byteSize
}
return totalByteSize
}
override fun vendAllocator(blockSize: Int): BlockAllocator {
if (blockSize <= 0) {
throw IllegalArgumentException("Invalid block size: $blockSize")
}
val result = allocators[blockSize]?.poll() ?: PooledBlockAllocator(blockSize)
removeExcess()
return result
}
private fun removeExcess() {
var totalByteSize = 0
val queuesIterator = allocators.values.iterator()
var isExcess = false
while (queuesIterator.hasNext()) {
val nextQueue = queuesIterator.next()
val iterator = nextQueue.iterator()
while (iterator.hasNext()) {
val allocator = iterator.next()
if (isExcess) {
iterator.remove()
continue
}
totalByteSize += allocator.byteSize
if (totalByteSize > POOL_THRESHOLD) {
iterator.remove()
isExcess = true
}
}
}
}
}

View File

@@ -1,29 +1,8 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.serialization
import org.assertj.core.api.Assertions.assertThat
fun getBinding(aClass: Class<*>, serializer: ObjectSerializer): Any = serializer.serializer.bindingProducer.getRootBinding(aClass)
fun getBindingProducer(serializer: ObjectSerializer): Any = serializer.serializer.bindingProducer
fun getBindingCount(producer: Any) = (producer as BindingProducer).bindingCount
fun testThreadLocalPooledBlockAllocatorProvider() {
val provider = PooledBlockAllocatorProvider()
var allocated = 1024
provider.vendAllocator(allocated).use { it.allocateBlock() }
assertThat(provider.byteSize).isEqualTo(allocated)
allocated += 1024 + 1
provider.vendAllocator(1024 + 1).use { it.allocateBlock() }
assertThat(provider.byteSize).isEqualTo(allocated)
allocated += PooledBlockAllocatorProvider.POOL_THRESHOLD
provider.vendAllocator(PooledBlockAllocatorProvider.POOL_THRESHOLD).use { it.allocateBlock() }
assertThat(provider.byteSize).isLessThanOrEqualTo(2049)
provider.vendAllocator(PooledBlockAllocatorProvider.POOL_THRESHOLD + 1).use { it.allocateBlock() }
assertThat(provider.byteSize).isLessThanOrEqualTo(allocated + 1)
}
fun getBindingCount(producer: Any) = (producer as BindingProducer).bindingCount

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.serialization
import com.intellij.openapi.util.SystemInfo
@@ -10,7 +10,6 @@ import org.junit.rules.TestName
import java.io.File
import java.nio.file.Paths
import java.util.*
import kotlin.collections.HashMap
class ObjectSerializerTest {
@Rule
@@ -21,11 +20,6 @@ class ObjectSerializerTest {
return test(bean, testName, writeConfiguration)
}
@Test
fun threadLocalPooledBlockAllocatorProvider() {
testThreadLocalPooledBlockAllocatorProvider()
}
@Test
fun `same bean binding regardless of type parameters`() {
val serializer = ObjectSerializer()