forked from oracle/graal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
265 additions
and
177 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/LogHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2018, 2018, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package org.graalvm.nativeimage; | ||
|
||
import org.graalvm.nativeimage.c.type.CCharPointer; | ||
import org.graalvm.word.UnsignedWord; | ||
|
||
/** | ||
* Implement this interface to create a custom log handler. The custom log handler must be installed | ||
* in the {@code ImageSingletons} at {@code Feature.duringSetup()} time like so: | ||
* | ||
* <pre> | ||
* class LogHandlerFeature implements Feature { | ||
* {@literal @}Override | ||
* public void duringSetup(DuringSetupAccess access) { | ||
* ImageSingletons.add(LogHandler.class, new CustomLogHandler()); | ||
* } | ||
* } | ||
* </pre> | ||
* | ||
* If no custom log handler is installed a default one would be provided at | ||
* {@code Feature.beforeAnalysis()} time. Installing a custom log handler at a later time, after the | ||
* default one has been installed, will result in an error. | ||
* | ||
*/ | ||
public interface LogHandler { | ||
|
||
static LogHandler get() { | ||
return ImageSingletons.lookup(LogHandler.class); | ||
} | ||
|
||
/** Writes the raw bytes. */ | ||
void log(CCharPointer bytes, UnsignedWord length); | ||
|
||
/** Forces the log to flush to its destination. */ | ||
void flush(); | ||
|
||
/** Exit the VM. Method must not return. No Java code should be run after this point. */ | ||
void fatalError(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...ratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/DefaultLogHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (c) 2018, 2018, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package com.oracle.svm.core.posix; | ||
|
||
import java.io.FileDescriptor; | ||
|
||
import com.oracle.svm.core.annotate.AutomaticFeature; | ||
import org.graalvm.nativeimage.Feature; | ||
import org.graalvm.nativeimage.ImageSingletons; | ||
import org.graalvm.nativeimage.LogHandler; | ||
import org.graalvm.nativeimage.c.type.CCharPointer; | ||
import org.graalvm.word.UnsignedWord; | ||
|
||
import com.oracle.svm.core.config.ConfigurationValues; | ||
|
||
@AutomaticFeature | ||
class DefaultLogHandlerFeature implements Feature { | ||
@Override | ||
public void beforeAnalysis(BeforeAnalysisAccess access) { | ||
/* An alternative log handler can be set in Feature.duringSetup(). */ | ||
if (!ImageSingletons.contains(LogHandler.class)) { | ||
/* | ||
* Install the default log handler in ImageSingletons such that if another feature tries | ||
* to install another log handler at a later point it will get an error. | ||
*/ | ||
LogHandler logHandler = new DefaultLogHandler(); | ||
ImageSingletons.add(LogHandler.class, logHandler); | ||
} | ||
} | ||
} | ||
|
||
public class DefaultLogHandler implements LogHandler { | ||
|
||
@Override | ||
public void log(CCharPointer bytes, UnsignedWord length) { | ||
if (!ConfigurationValues.getOSInterface().writeBytesUninterruptibly(getOutputFile(), bytes, length)) { | ||
/* | ||
* We are in a low-level log routine and output failed, so there is little we can do. | ||
*/ | ||
ConfigurationValues.getOSInterface().abort(); | ||
} | ||
} | ||
|
||
@Override | ||
public void flush() { | ||
ConfigurationValues.getOSInterface().flush(getOutputFile()); | ||
/* ignore error -- they're benign */ | ||
} | ||
|
||
@Override | ||
public void fatalError() { | ||
ConfigurationValues.getOSInterface().abort(); | ||
} | ||
|
||
/* Allow subclasses to customize the file descriptor that we write to. */ | ||
private static FileDescriptor getOutputFile() { | ||
return FileDescriptor.err; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.