GraalVM Commands

Published: 2019-01-25, Updated: 2020-08-08

Links

Substituindo clases

@TargetClass(className = "org.apache.kafka.common.utils.Crc32C$Java9ChecksumFactory")
@Substitute
final class Java9ChecksumFactory {
  @Substitute
  public Checksum create() {
    return new CRC32();
  }
}

Exemplo para compilar um jar

native-image --no-server --no-fallback -H:Class=com.mageddo.jdbi.JdbiMain -cp ./build/libs/jdbi-all.jar

Libs suportadas

Okhttp

Configurar proprio logger

class ReflectionClasses implements Feature {
	@Override
	public void duringSetup(DuringSetupAccess access) {
		ImageSingletons.add(LogHandler.class, new NopLogHanler());
	}
}

Reflection

Opções de configuração de reflection e da graalvm

native-image --expert-options

Configurar reflections e argumentos da graalvm via META-INF

src/main/resources/META-INF/native-image/io.netty/transport/native-image.properties

Args = -H:ReflectionConfigurationResources=${.}/reflection-config.json

src/main/resources/META-INF/native-image/io.netty/transport/reflection-config.json

[
  {
      "name": "io.netty.channel.socket.nio.NioServerSocketChannel",
      "methods": [
        { "name": "<init>", "parameterTypes": [] }
      ]
  },
  {
      "name": "sun.nio.ch.SelectorImpl",
      "fields": [
        { "name": "selectedKeys",  "allowUnsafeAccess" : true},
        { "name": "publicSelectedKeys",  "allowUnsafeAccess" : true}
      ]
  },
	{
		"name": "java.sql.Connection",
		"allDeclaredFields" : true
	},
	{
		"name": "org.springframework.transaction.TransactionDefinition",
		"allDeclaredFields" : true
	},
	{
		"name": "java.sql.Statement[]",
		"allPublicConstructors": true,
		"allDeclaredConstructors": true
	}
]

Gerar reflection usando o agent da gralvm

java -agentlib:native-image-agent=config-output-dir=build/

ou

java -agentlib:native-image-agent=config-merge-dir=/tmp/reflection -cp ./build/libs/jdbi-all.jar com.mageddo.jdbi.JdbiMain

Examples

Utils

Saber se está rodando em uma NativeImage ou não

ImageInfo.inImageRuntimeCode()

Pegar o path do exectuável que está executando

ProcessProperties.getExecutableName()

Issues relacionados

Keywords

graalvm commands, graal commands


Resident Evil 4 HD Commands Micronaut Commands

Comments