Skip to content

Instantly share code, notes, and snippets.

View anatawa12's full-sized avatar

anatawa12 anatawa12

View GitHub Profile
@anatawa12
anatawa12 / README.md
Last active April 27, 2020 09:34
gradle-mvn-push.gradle

how to use

add to build.gradle

apply from: 'https://gist.githubusercontent.com/anatawa12/75cb9a093bc93ed473a7ca2ac489eaf9/raw/aec03f39610fa231acfbb000855a337d63d59510/gradle-mvn-push.gradle'

add to ~/.gradle/gradle.properties see [http://gradle.monochromeroad.com/docs/userguide/signing_plugin.html] for signing properties

NEXUS_USERNAME=<username>
NEXUS_PASSWORD=
@anatawa12
anatawa12 / MAIN.MD
Last active November 28, 2022 15:24
How to execute runClient in ForgeGradle for 1.12 or older with newest jdk8.

go to TL;DR

日本語

since jdk 8u242, runClient Task and client run with GradleStart class will never succeed with error below:

[18:48:19] [main/ERROR] [LaunchWrapper]: Unable to launch
java.lang.reflect.InvocationTargetException: null
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_242]

方法

AppClassLoaderにApache Commonsのライブラリを追加します。

実際は以下のように、リフレクションで追加します。 CoreModで使用するのであればIFMLLoadingPluginの実装クラスのコンストラクタ内で実行するのが、 通常のmodであれば@Modのクラスのコンストラクタ内で実行するのがいいかと思われます。

val addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
@anatawa12
anatawa12 / .README.md
Last active October 8, 2020 12:57
Dead lock issue

thread-dump-by-java.txt: thread dump taken by jcmd. native-frame-of-invisible-get-lock-of-classloader-by-lldb-debugger.txt: backtrace of native stack by lldb.

thread-dump-by-java.txt#L504 says that "Snooper Timer" thread is waiting to lock monitor of PluginClassLoader instance. But thread-dump-by-java.txt#L537 says "Snooper Timer" thread is not waiting for any lock. Therefore I wanted to take thread dump including native thread (mixed mode stack trace) but jstack throws an error and not able to take mixed stack trace because of known bug (JDK-8160376)

@anatawa12
anatawa12 / 0-object-input-stream-classloader-test.md
Last active February 6, 2021 03:02
object-input-stream-classloader-test
@anatawa12
anatawa12 / WeakIdentityHashMap.kt
Created December 16, 2020 02:10
WeakIdentityHashMap (not tested, HashMap-backed)
private class WeakIdentityHashMap<K : Any, V> : MutableMap<K, V> {
private val backed = HashMap<Key<K>, V>()
private val queue = ReferenceQueue<K>()
private fun clean() {
while (true) {
val v = queue.poll() ?: return
backed.remove(v)
}
@anatawa12
anatawa12 / Verification Tableについて.md
Last active January 12, 2021 04:01
Verification Tableについて聞かれたからざっと書いたもの

Verification Tableについて

JVMは誤動作や脆弱性回避のために、コードを実行する前にスタック及びローカル変数の状態を確認します。
例えば

aload_0
istore_1

などと並んでいると(実行前に)エラーが発生します。

しかし、ジャンプ命令があるとこの追跡が難しくなります。
そのため、ジャンプ命令のジャンプ先の位置にスタックおよびローカル変数の状態を保存します。例えば

@anatawa12
anatawa12 / 0.MethodClassLoadingTesting.java
Last active February 5, 2021 02:34
メソッドの引数などのクラスロードのタイミングの調査
import java.util.Objects;
class MethodClassLoadingTesting {
static {
System.out.println(" MethodClassLoadingTesting loaded");
}
public static void main(String[] args) {
System.out.println("loading MethodHolderClass");
MethodHolderClass.loader();
@anatawa12
anatawa12 / dropLast-for-sequence.kt
Created March 16, 2021 07:22
dropLast for Sequence<T>
// SPDX-License-Identifier: CC0-1.0
// (c) anatawa12 2021
fun <T> Sequence<T>.dropLast(n: Int): Sequence<T> = when {
n < 0 -> throw IllegalArgumentException("Requested element count $n is less than zero.")
n == 0 -> this
else -> DropLastSequence(this, n)
}
private class DropLastSequence<T>(private val seq: Sequence<T>, val count: Int) : Sequence<T> {
@anatawa12
anatawa12 / shadowing-and-relocating.gradle.kts
Created March 21, 2021 06:02
the example script to shadow and relocate kotlin for ForgeGradle
import com.anatawa12.javaStabGen.gradle.GenerateJavaStab
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
kotlin("jvm") version "<version>"
id("com.github.johnrengelman.shadow") version "6.1.0"
}
val shade by configurations.creating
configurations.compile.get().extendsFrom(shade)