Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proper logging #46

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ dependency-reduced-pom.xml
hotspot.log
.directory
.java-version
.graal-install
.graal-install
hs_err_pid*.log
server.log
dumps
*.orig
*.rej
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.jboss.jandex.IndexView;
import org.jboss.jandex.Indexer;
import org.jboss.jandex.MethodInfo;
import org.jboss.logging.Logger;
import org.jboss.protean.arc.ArcContainer;
import org.jboss.protean.arc.processor.BeanProcessor;
import org.jboss.protean.arc.processor.BeanProcessor.Builder;
Expand All @@ -44,6 +45,7 @@
public class ArcAnnotationProcessor implements ResourceProcessor {

private static final DotName JAVA_LANG_OBJECT = DotName.createSimple(Object.class.getName());
private static final Logger log = Logger.getLogger("org.jboss.shamrock.arc.deployment.processor");

@Inject
BeanDeployment beanDeployment;
Expand Down Expand Up @@ -120,7 +122,7 @@ public void writeResource(Resource resource) throws IOException {
}
}
}
System.out.println("Add " + (isAppClass ? "APP" : "FWK") + " class: " + resource.getFullyQualifiedName());
log.infof("Add %s class: %s", (isAppClass ? "APP" : "FWK"), resource.getFullyQualifiedName());
processorContext.addGeneratedClass(isAppClass, resource.getName(), resource.getData());
break;
case SERVICE_PROVIDER:
Expand Down Expand Up @@ -156,7 +158,7 @@ private void indexBeanClass(String beanClass, Indexer indexer, IndexView shamroc
}
ClassInfo beanInfo = shamrockIndex.getClassByName(beanClassName);
if (beanInfo == null) {
System.out.println("Index bean class: " + beanClass);
log.infof("Index bean class: %s", beanClass);
try (InputStream stream = ArcAnnotationProcessor.class.getClassLoader().getResourceAsStream(beanClass.replace('.', '/') + ".class")) {
beanInfo = indexer.index(stream);
additionalIndex.add(beanInfo.name());
Expand All @@ -171,7 +173,7 @@ private void indexBeanClass(String beanClass, Indexer indexer, IndexView shamroc
if (!additionalIndex.contains(annotationName) && shamrockIndex.getClassByName(annotationName) == null) {
try (InputStream annotationStream = ArcAnnotationProcessor.class.getClassLoader()
.getResourceAsStream(annotationName.toString().replace('.', '/') + ".class")) {
System.out.println("Index annotation: " + annotationName);
log.infof("Index annotation: %s", annotationName);
indexer.index(annotationStream);
additionalIndex.add(annotationName);
} catch (IOException e) {
Expand All @@ -192,7 +194,7 @@ private void indexBeanClass(String beanClass, Indexer indexer, IndexView shamroc
}
ClassInfo beanInfo = shamrockIndex.getClassByName(beanClassName);
if (beanInfo == null) {
System.out.println("Index bean class: " + beanClass);
log.infof("Index bean class: %s", beanClass);
try (InputStream stream = new ByteArrayInputStream(beanData)) {
beanInfo = indexer.index(stream);
additionalIndex.add(beanInfo.name());
Expand All @@ -207,7 +209,7 @@ private void indexBeanClass(String beanClass, Indexer indexer, IndexView shamroc
if (!additionalIndex.contains(annotationName) && shamrockIndex.getClassByName(annotationName) == null) {
try (InputStream annotationStream = ArcAnnotationProcessor.class.getClassLoader()
.getResourceAsStream(annotationName.toString().replace('.', '/') + ".class")) {
System.out.println("Index annotation: " + annotationName);
log.infof("Index annotation: %s", annotationName);
indexer.index(annotationStream);
additionalIndex.add(annotationName);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import static org.jboss.protean.gizmo.MethodDescriptor.ofConstructor;
import static org.jboss.protean.gizmo.MethodDescriptor.ofMethod;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
Expand All @@ -26,6 +30,7 @@
import java.util.List;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -149,6 +154,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
throw new RuntimeException(e);
}
}
processorContext.writeProperties(root.toFile());
processorContext.writeMainClass();
processorContext.writeReflectionAutoFeature();
} finally {
Expand Down Expand Up @@ -178,6 +184,7 @@ private final class ProcessorContextImpl implements ProcessorContext {
private final Set<String> runtimeInitializedClasses = new HashSet<>();
private final Set<List<String>> proxyClasses = new HashSet<>();
private final Map<String, Object> properties = new HashMap<>();
private final Map<String, String> systemProperties = new HashMap<>();

@Override
public BytecodeRecorder addStaticInitTask(int priority) {
Expand Down Expand Up @@ -299,6 +306,11 @@ public void addProxyDefinition(String... proxyClasses) {
this.proxyClasses.add(Arrays.asList(proxyClasses));
}

@Override
public void addNativeImageSystemProperty(final String name, final String value) {
systemProperties.put(name, value);
}

@Override
public boolean isCapabilityPresent(String capability) {
return capabilities.contains(capability);
Expand All @@ -314,6 +326,15 @@ public <T> T getProperty(String key) {
return (T) properties.get(key);
}

void writeProperties(File output) throws IOException {
final Properties properties = new Properties();
properties.putAll(systemProperties);
try (FileOutputStream os = new FileOutputStream(new File(output, "native-image.properties"))) {
try (OutputStreamWriter osw = new OutputStreamWriter(os, StandardCharsets.UTF_8)) {
properties.store(osw, "Generated properties (do not edit)");
}
}
}

void writeMainClass() throws IOException {

Expand Down Expand Up @@ -389,6 +410,33 @@ void writeReflectionAutoFeature() throws IOException {

}

// hack in reinitialization of process info classes
{
ResultHandle array = beforeAn.newArray(Class.class, beforeAn.load(1));
ResultHandle thisClass = beforeAn.loadClass(GRAAL_AUTOFEATURE);
ResultHandle cl = beforeAn.invokeVirtualMethod(ofMethod(Class.class, "getClassLoader", ClassLoader.class), thisClass);
{
ExceptionTable tc = beforeAn.addTryCatch();
ResultHandle clazz = beforeAn.invokeStaticMethod(ofMethod(Class.class, "forName", Class.class, String.class, boolean.class, ClassLoader.class), beforeAn.load("org.wildfly.common.net.HostName"), beforeAn.load(false), cl);
beforeAn.writeArrayValue(array, beforeAn.load(0), clazz);
beforeAn.invokeStaticMethod(MethodDescriptor.ofMethod("org.graalvm.nativeimage.RuntimeClassInitialization", "rerunClassInitialization", void.class, Class[].class), array);

CatchBlockCreator cc = tc.addCatchClause(Throwable.class);
cc.invokeVirtualMethod(ofMethod(Throwable.class, "printStackTrace", void.class), cc.getCaughtException());
tc.complete();
}
{
ExceptionTable tc = beforeAn.addTryCatch();
ResultHandle clazz = beforeAn.invokeStaticMethod(ofMethod(Class.class, "forName", Class.class, String.class, boolean.class, ClassLoader.class), beforeAn.load("org.wildfly.common.os.Process"), beforeAn.load(false), cl);
beforeAn.writeArrayValue(array, beforeAn.load(0), clazz);
beforeAn.invokeStaticMethod(MethodDescriptor.ofMethod("org.graalvm.nativeimage.RuntimeClassInitialization", "rerunClassInitialization", void.class, Class[].class), array);

CatchBlockCreator cc = tc.addCatchClause(Throwable.class);
cc.invokeVirtualMethod(ofMethod(Throwable.class, "printStackTrace", void.class), cc.getCaughtException());
tc.complete();
}
}

if (!proxyClasses.isEmpty()) {
ResultHandle proxySupportClass = beforeAn.loadClass("com.oracle.svm.core.jdk.proxy.DynamicProxyRegistry");
ResultHandle proxySupport = beforeAn.invokeStaticMethod(ofMethod("org.graalvm.nativeimage.ImageSingletons", "lookup", Object.class, Class.class), proxySupportClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ public interface ProcessorContext {
*/
void addProxyDefinition(String ... proxyClasses);

/**
* Set a system property to be passed in to the native image tool.
*
* @param name the property name (must not be {@code null})
* @param value the property value
*/
void addNativeImageSystemProperty(String name, String value);

/**
*
* @param capability
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class ShamrockConfig {

public static ShamrockConfig INSTANCE = new ShamrockConfig();
public static final ShamrockConfig INSTANCE = new ShamrockConfig();


private static final Config config = ConfigProvider.getConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
Expand Down Expand Up @@ -115,6 +116,13 @@ public ConfigNode get(String key) {
return NULL;
}

public Set<String> getChildKeys() {
if (node instanceof Map) {
return ((Map) node).keySet();
}
return Collections.emptySet();
}

public Boolean asBoolean() {
if (node instanceof Boolean) {
return (Boolean) node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.nio.file.Files;
Expand All @@ -29,8 +27,6 @@
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;

import sun.misc.URLClassPath;

public class RuntimeClassLoader extends ClassLoader implements ClassOutput, Consumer<List<Function<String, Function<ClassVisitor, ClassVisitor>>>> {

private final Map<String, byte[]> appClasses = new HashMap<>();
Expand Down
16 changes: 14 additions & 2 deletions core/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,20 @@
<artifactId>smallrye-config</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-embedded</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.slf4j</groupId>
<artifactId>slf4j-jboss-logging</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm</groupId>
<artifactId>graal-sdk</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.graalvm</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*/
public class Shamrock {

private static final Logger logger = Logger.getLogger("shamrock");

public static void main(String... args) throws Exception {
try {
//check if the main class is on the classpath
Expand All @@ -31,7 +29,7 @@ public static void main(String... args) throws Exception {
Method mainMethod = main.getDeclaredMethod("main", String[].class);
mainMethod.invoke(null, (Object) args);
} catch (Exception e) {
logger.log(Level.WARNING, "Could not find wiring classes, using development mode");
Logger.getLogger("shamrock").log(Level.WARNING, "Could not find wiring classes, using development mode");
Runnable runnable;
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jboss.shamrock.runtime;

import org.jboss.logging.Logger;

/**
* Class that is responsible for printing out timing results.
* <p>
Expand All @@ -12,7 +14,7 @@ public class Timing {

public static void staticInitStarted() {
if(bootStartTime < 0) {
bootStartTime = System.currentTimeMillis();
bootStartTime = System.nanoTime();
}
}

Expand All @@ -23,11 +25,12 @@ public static void mainStarted() {
}

public static void restart() {
bootStartTime = System.currentTimeMillis();
bootStartTime = System.nanoTime();
}

public static void printStartupTime() {
System.out.println("Shamrock started in " + (System.currentTimeMillis() - bootStartTime) + "ms");
final long time = System.nanoTime() - bootStartTime + 500;
Logger.getLogger("org.jboss.shamrock").infof("Shamrock started in %d.%03dms", Long.valueOf(time / 1_000_000), Long.valueOf(time % 1_000_000 / 1_000));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class TimingReplacement {

@Substitute
public static void mainStarted() {
bootStartTime = System.currentTimeMillis();
bootStartTime = System.nanoTime();
}

}

This file was deleted.

This file was deleted.

Loading