Loading ravenwood/tests/coretest/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ java_defaults { strip_mockito: true, }, auto_gen_config: true, jarjar_rules: "empty.txt", } android_ravenwood_test { Loading ravenwood/tests/coretest/empty.txt 0 → 100644 +0 −0 Empty file added. ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/HostStubGenLogger.kt +4 −4 Original line number Diff line number Diff line Loading @@ -226,7 +226,9 @@ open class HostStubGenLogger(val options: HostStubGenLoggerOptions) { } override fun write(cbuf: CharArray, off: Int, len: Int) { println(level, String(cbuf, off, len)) String(cbuf, off, len).lines().forEach { println(level, it) } } } } Loading @@ -244,9 +246,9 @@ private class BufferedLogger(base: HostStubGenLogger) : HostStubGenLogger(base) it.println(indent, message) } } output.clear() it.flush() } output.clear() } override fun println(level: LogLevel, message: String) { Loading Loading @@ -330,8 +332,6 @@ interface LogPrinter { fun println(indent: Int, message: String) // TODO: This should be removed once MultiplexingWriter starts applying indent, at which point // println() should be used instead. fun write(cbuf: CharArray, off: Int, len: Int) fun flush() Loading ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/utils/ConcurrentZipFile.kt +15 −6 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ import java.io.InputStream import java.nio.ByteBuffer import java.nio.channels.FileChannel import java.util.concurrent.CountDownLatch import java.util.concurrent.ExecutorService import java.util.concurrent.Executor import java.util.concurrent.Executors import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicInteger Loading @@ -39,6 +39,8 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream import org.apache.commons.compress.archivers.zip.ZipFile // Enable to debug concurrency issues const val DISABLE_PARALLELISM = false const val DEFAULT_SHARD_COUNT = 20 const val MINIMUM_BATCH_SIZE = 100 Loading Loading @@ -148,7 +150,7 @@ class ConcurrentListMapper<T>(val list: MutableList<T?>) { inline fun process(mapper: (T) -> T?) { while (true) { val idx = currentIndex.incrementAndGet() val idx = currentIndex.getAndIncrement() if (idx < list.size) { list[idx]?.let { list[idx] = mapper(it) } continue Loading @@ -163,7 +165,7 @@ class ConcurrentZipFile( parallelism: Int, ) { val entries: MutableList<ZipEntryData?> val executor: ExecutorService val executor: Executor val shardCount: Int init { Loading @@ -175,10 +177,16 @@ class ConcurrentZipFile( .map { ZipEntryData.Entry(it, mappedBytes) } .toMutableList() } if (DISABLE_PARALLELISM) { shardCount = 1 // Directly run on the same thread as the caller executor = Executor { r -> r.run() } } else { val count = min(parallelism, Runtime.getRuntime().availableProcessors()) shardCount = min(count, entries.size / MINIMUM_BATCH_SIZE + 1) executor = Executors.newFixedThreadPool(shardCount) } } inline fun forEach(action: (ZipEntryData) -> Unit) { entries.asSequence().filterNotNull().forEach(action) Loading Loading @@ -206,6 +214,7 @@ class ConcurrentZipFile( } catch (e: Throwable) { exception.compareAndSet(null, e) } finally { log.flush() latch.countDown() } } Loading Loading
ravenwood/tests/coretest/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,7 @@ java_defaults { strip_mockito: true, }, auto_gen_config: true, jarjar_rules: "empty.txt", } android_ravenwood_test { Loading
ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/HostStubGenLogger.kt +4 −4 Original line number Diff line number Diff line Loading @@ -226,7 +226,9 @@ open class HostStubGenLogger(val options: HostStubGenLoggerOptions) { } override fun write(cbuf: CharArray, off: Int, len: Int) { println(level, String(cbuf, off, len)) String(cbuf, off, len).lines().forEach { println(level, it) } } } } Loading @@ -244,9 +246,9 @@ private class BufferedLogger(base: HostStubGenLogger) : HostStubGenLogger(base) it.println(indent, message) } } output.clear() it.flush() } output.clear() } override fun println(level: LogLevel, message: String) { Loading Loading @@ -330,8 +332,6 @@ interface LogPrinter { fun println(indent: Int, message: String) // TODO: This should be removed once MultiplexingWriter starts applying indent, at which point // println() should be used instead. fun write(cbuf: CharArray, off: Int, len: Int) fun flush() Loading
ravenwood/tools/hoststubgen/lib/com/android/hoststubgen/utils/ConcurrentZipFile.kt +15 −6 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ import java.io.InputStream import java.nio.ByteBuffer import java.nio.channels.FileChannel import java.util.concurrent.CountDownLatch import java.util.concurrent.ExecutorService import java.util.concurrent.Executor import java.util.concurrent.Executors import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicInteger Loading @@ -39,6 +39,8 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream import org.apache.commons.compress.archivers.zip.ZipFile // Enable to debug concurrency issues const val DISABLE_PARALLELISM = false const val DEFAULT_SHARD_COUNT = 20 const val MINIMUM_BATCH_SIZE = 100 Loading Loading @@ -148,7 +150,7 @@ class ConcurrentListMapper<T>(val list: MutableList<T?>) { inline fun process(mapper: (T) -> T?) { while (true) { val idx = currentIndex.incrementAndGet() val idx = currentIndex.getAndIncrement() if (idx < list.size) { list[idx]?.let { list[idx] = mapper(it) } continue Loading @@ -163,7 +165,7 @@ class ConcurrentZipFile( parallelism: Int, ) { val entries: MutableList<ZipEntryData?> val executor: ExecutorService val executor: Executor val shardCount: Int init { Loading @@ -175,10 +177,16 @@ class ConcurrentZipFile( .map { ZipEntryData.Entry(it, mappedBytes) } .toMutableList() } if (DISABLE_PARALLELISM) { shardCount = 1 // Directly run on the same thread as the caller executor = Executor { r -> r.run() } } else { val count = min(parallelism, Runtime.getRuntime().availableProcessors()) shardCount = min(count, entries.size / MINIMUM_BATCH_SIZE + 1) executor = Executors.newFixedThreadPool(shardCount) } } inline fun forEach(action: (ZipEntryData) -> Unit) { entries.asSequence().filterNotNull().forEach(action) Loading Loading @@ -206,6 +214,7 @@ class ConcurrentZipFile( } catch (e: Throwable) { exception.compareAndSet(null, e) } finally { log.flush() latch.countDown() } } Loading