Browse Source

Merge pull request #1412 in CORE/base-third from release/10.0 to final/10.0

* commit '25fd2ad984c9f377a09a13c4bbbb474eb14864f3':
  KERNEL-6186 升级J2V8 & V8
  REPORT-42043 fanruan.log无法分割-代码质量
  REPORT-42043 fanruan.log无法分割-代码质量
  REPORT-42043 fanruan.log无法分割-代码质量
  REPORT-42043 fanruan.log无法分割-加个volatile
  REPORT-42043 fanruan.log无法分割-多线程问题
  REPORT-42043 fanruan.log无法分割-代码质量
  REPORT-42043 fanruan.log无法分割
final/10.0
superman 4 years ago
parent
commit
5e431502db
  1. 5
      fine-j2v8/src/main/java/com/eclipsesource/v8/PlatformDetector.java
  2. 5
      fine-j2v8/src/main/java/com/eclipsesource/v8/SignatureProvider.java
  3. 77
      fine-j2v8/src/main/java/com/eclipsesource/v8/V8.java
  4. 17
      fine-j2v8/src/main/java/com/eclipsesource/v8/V8OutOfMemoryError.java
  5. 11
      fine-j2v8/src/main/java/com/eclipsesource/v8/V8Value.java
  6. 7
      fine-j2v8/src/main/java/com/eclipsesource/v8/inspector/DebuggerConnectionListener.java
  7. 67
      fine-j2v8/src/main/java/com/eclipsesource/v8/inspector/V8Inspector.java
  8. 7
      fine-j2v8/src/main/java/com/eclipsesource/v8/inspector/V8InspectorDelegate.java
  9. 3
      fine-j2v8/src/main/java/com/eclipsesource/v8/utils/V8Executor.java
  10. BIN
      fine-j2v8/src/main/resources/libj2v8-linux-aarch_64.so
  11. BIN
      fine-j2v8/src/main/resources/libj2v8-linux-x86_64.so
  12. BIN
      fine-j2v8/src/main/resources/libj2v8-macosx-x86_64.dylib
  13. BIN
      fine-j2v8/src/main/resources/libj2v8-windows-x86_64.dll
  14. BIN
      fine-j2v8/src/main/resources/libj2v8_win32_x86.dll
  15. 67
      fine-log4j/src/main/java/com/fr/third/apache/log4j/DailyRollingFileAppender.java

5
fine-j2v8/src/main/java/com/eclipsesource/v8/PlatformDetector.java

@ -124,7 +124,6 @@ public class PlatformDetector {
if (OS.isAndroid()) {
return "google";
}
//如果if条件全部不符合,就会陷入死循环,代码存在风险
//throw new UnsatisfiedLinkError("Unsupported vendor: " + getName());
return null;
@ -286,10 +285,10 @@ public class PlatformDetector {
if (value.matches("^(sparcv9|sparc64)$")) {
return "sparc_64";
}
if (value.matches("^(arm|arm32)$")) {
if (value.matches("^(arm|arm32)$") || value.startsWith("armv7")) {
return "arm_32";
}
if ("aarch64".equals(value)) {
if ("aarch64".equals(value) || value.startsWith("armv8")) {
return "aarch_64";
}
if (value.matches("^(ppc|ppc32)$")) {

5
fine-j2v8/src/main/java/com/eclipsesource/v8/SignatureProvider.java

@ -0,0 +1,5 @@
package com.eclipsesource.v8;
public interface SignatureProvider {
public byte[] getSignature(String uri);
}

77
fine-j2v8/src/main/java/com/eclipsesource/v8/V8.java

@ -20,6 +20,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import com.eclipsesource.v8.inspector.V8InspectorDelegate;
import com.eclipsesource.v8.utils.V8Executor;
import com.eclipsesource.v8.utils.V8Map;
import com.eclipsesource.v8.utils.V8Runnable;
@ -47,6 +48,7 @@ public class V8 extends V8Object {
private Map<String, Object> data = null;
private final V8Locker locker;
private SignatureProvider signatureProvider = null;
private long objectReferences = 0;
private long v8RuntimePtr = 0;
private List<Releasable> resources = null;
@ -162,6 +164,10 @@ public class V8 extends V8Object {
return runtime;
}
public void setSignatureProvider(final SignatureProvider signatureProvider) {
this.signatureProvider = signatureProvider;
}
/**
* Adds a ReferenceHandler to track when new V8Objects are created.
*
@ -276,6 +282,20 @@ public class V8 extends V8Object {
objectHandle = _getGlobalObject(v8RuntimePtr);
}
public long createInspector(final V8InspectorDelegate inspectorDelegate, final String contextName) {
return _createInspector(v8RuntimePtr, inspectorDelegate, contextName);
}
public void dispatchProtocolMessage(final long V8InspectorPtr, final String protocolMessage) {
checkThread();
_dispatchProtocolMessage(v8RuntimePtr, V8InspectorPtr, protocolMessage);
}
public void schedulePauseOnNextStatement(final long V8InspectorPtr, final String reason) {
checkThread();
_schedulePauseOnNextStatement(v8RuntimePtr, V8InspectorPtr, reason);
}
/**
* Returns an UNDEFINED constant.
*
@ -670,16 +690,51 @@ public class V8 extends V8Object {
* Primitives will be boxed.
*
* @param script The script to execute.
* @param scriptName The name of the script
* @param uri The name of the script
*
* @return The result of the script as a Java Object.
*/
public Object executeScript(final String script, final String uri) {
checkThread();
checkScript(script);
return executeScript(getV8RuntimePtr(), UNKNOWN, script, uri, 0);
}
/**
* Executes a JS Script on this runtime and returns the result as a Java Object.
* Primitives will be boxed.
*
* @param script The script to execute.
* @param uri The name of the script
* @param lineNumber The line number that is considered to be the first line of
* the script. Typically 0, but could be set to another value for exception stack trace purposes.
*
* @return The result of the script as a Java Object.
*/
public Object executeScript(final String script, final String scriptName, final int lineNumber) {
public Object executeScript(final String script, final String uri, final int lineNumber) {
checkThread();
checkScript(script);
return executeScript(getV8RuntimePtr(), UNKNOWN, script, uri, lineNumber);
}
/**
* Executes a JS Script module on this runtime and returns the result as a Java Object.
* Primitives will be boxed.
*
* If the script does not match the signature (as verified with the public key) then a
* V8SecurityException will be thrown.
*
* @param script The signed script to execute
* @param modulePrefix The module prefix
* @param modulePostfix The module postfix
* @param uri The name of the script
*
* @return The result of the script as a Java Object.
*/
public Object executeModule(final String script, final String modulePrefix, final String modulePostfix, final String uri) {
checkThread();
checkScript(script);
return executeScript(getV8RuntimePtr(), UNKNOWN, script, scriptName, lineNumber);
return executeScript(getV8RuntimePtr(), UNKNOWN, modulePrefix + script + modulePostfix, uri, 0);
}
/**
@ -755,7 +810,7 @@ public class V8 extends V8Object {
*
* @return The unique build ID of the Native library.
*/
public long getBuildID() {
public static long getBuildID() {
return _getBuildID();
}
@ -1321,6 +1376,10 @@ public class V8 extends V8Object {
_addArrayNullItem(v8RuntimePtr, arrayHandle);
}
protected String getConstructorName(final long v8RuntimePtr, final long objectHandle) {
return _getConstructorName(v8RuntimePtr, objectHandle);
}
protected int getType(final long v8RuntimePtr, final long objectHandle) {
return _getType(v8RuntimePtr, objectHandle);
}
@ -1409,6 +1468,12 @@ public class V8 extends V8Object {
private native long _createIsolate(String globalAlias);
private native long _createInspector(long v8RuntimePtr, final V8InspectorDelegate inspectorDelegate, final String contextName);
private native void _dispatchProtocolMessage(final long v8RuntimePtr, long v8InspectorPtr, final String protocolMessage);
private native void _schedulePauseOnNextStatement(final long v8RuntimePtr, long v8InspectorPtr, final String reason);
private native int _executeIntegerScript(long v8RuntimePtr, final String script, final String scriptName, final int lineNumber);
private native double _executeDoubleScript(long v8RuntimePtr, final String script, final String scriptName, final int lineNumber);
@ -1519,6 +1584,8 @@ public class V8 extends V8Object {
private native void _setPrototype(long v8RuntimePtr, long objectHandle, long prototypeHandle);
private native String _getConstructorName(long v8RuntimePtr, long objectHandle);
private native int _getType(long v8RuntimePtr, long objectHandle);
private native int _getType(long v8RuntimePtr, long objectHandle, final int index, final int length);
@ -1581,7 +1648,7 @@ public class V8 extends V8Object {
private native long _getGlobalObject(final long v8RuntimePtr);
private native long _getBuildID();
private native static long _getBuildID();
private native static void _startNodeJS(final long v8RuntimePtr, final String fileName);

17
fine-j2v8/src/main/java/com/eclipsesource/v8/V8OutOfMemoryError.java

@ -0,0 +1,17 @@
package com.eclipsesource.v8;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2020-11-26
*/
public class V8OutOfMemoryError extends V8RuntimeException {
V8OutOfMemoryError(final String message) {
super(message);
}
V8OutOfMemoryError() {
super();
}
}

11
fine-j2v8/src/main/java/com/eclipsesource/v8/V8Value.java

@ -143,6 +143,17 @@ abstract public class V8Value implements Releasable {
}
}
/**
* Returns a constructor name of the V8 Value.
*
* @return The V8Value constructor name as a string.
*/
public String getConstructorName() {
v8.checkThread();
v8.checkReleased();
return v8.getConstructorName(v8.getV8RuntimePtr(), objectHandle);
}
/**
* Determines if this value is undefined.
*

7
fine-j2v8/src/main/java/com/eclipsesource/v8/inspector/DebuggerConnectionListener.java

@ -0,0 +1,7 @@
package com.eclipsesource.v8.inspector;
public interface DebuggerConnectionListener {
public void onDebuggerConnected();
public void onDebuggerDisconnected();
}

67
fine-j2v8/src/main/java/com/eclipsesource/v8/inspector/V8Inspector.java

@ -0,0 +1,67 @@
package com.eclipsesource.v8.inspector;
import java.util.ArrayList;
import java.util.List;
import com.eclipsesource.v8.V8;
import com.eclipsesource.v8.V8Object;
public class V8Inspector {
private V8 runtime;
private long inspectorPtr = 0;
private boolean waitingForConnection = true;
private List<DebuggerConnectionListener> debuggerConnectionListeners;
protected V8Inspector(final V8 runtime, final V8InspectorDelegate inspectorDelegate, final String contextName) {
this.runtime = runtime;
inspectorPtr = runtime.createInspector(inspectorDelegate, contextName);
debuggerConnectionListeners = new ArrayList<DebuggerConnectionListener>();
}
public static V8Inspector createV8Inspector(final V8 runtime, final V8InspectorDelegate inspectorDelegate, final String contextName) {
return new V8Inspector(runtime, inspectorDelegate, contextName);
}
public static V8Inspector createV8Inspector(final V8 runtime, final V8InspectorDelegate inspectorDelegate) {
return new V8Inspector(runtime, inspectorDelegate, null);
}
public void dispatchProtocolMessage(final String protocolMessage) {
try {
runtime.dispatchProtocolMessage(inspectorPtr, protocolMessage);
if (waitingForConnection) {
verifyDebuggerConnection(protocolMessage);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void addDebuggerConnectionListener(final DebuggerConnectionListener listener) {
debuggerConnectionListeners.add(listener);
}
public void removeDebuggerConnectionListener(final DebuggerConnectionListener listener) {
debuggerConnectionListeners.remove(listener);
}
private void verifyDebuggerConnection(final String protocolMessage) {
V8Object json = null;
try {
json = runtime.executeObjectScript("JSON.parse(JSON.stringify(" + protocolMessage + "))");
if (json.getString("method").equals("Runtime.runIfWaitingForDebugger")) {
waitingForConnection = false;
runtime.schedulePauseOnNextStatement(inspectorPtr, "");
for (DebuggerConnectionListener listener : debuggerConnectionListeners) {
listener.onDebuggerConnected();
}
}
} finally {
if (json != null) {
json.close();
}
}
}
}

7
fine-j2v8/src/main/java/com/eclipsesource/v8/inspector/V8InspectorDelegate.java

@ -0,0 +1,7 @@
package com.eclipsesource.v8.inspector;
public interface V8InspectorDelegate {
public void onResponse(String message);
public void waitFrontendMessageOnPause();
}

3
fine-j2v8/src/main/java/com/eclipsesource/v8/utils/V8Executor.java

@ -125,9 +125,6 @@ public class V8Executor extends Thread {
if (scriptResult instanceof Releasable) {
((Releasable) scriptResult).release();
}
if (scriptResult instanceof Releasable) {
((Releasable) scriptResult).release();
}
}
while (!forceTerminating && longRunning) {
synchronized (this) {

BIN
fine-j2v8/src/main/resources/libj2v8-linux-aarch_64.so

Binary file not shown.

BIN
fine-j2v8/src/main/resources/libj2v8-linux-x86_64.so

Binary file not shown.

BIN
fine-j2v8/src/main/resources/libj2v8-macosx-x86_64.dylib

Binary file not shown.

BIN
fine-j2v8/src/main/resources/libj2v8-windows-x86_64.dll

Binary file not shown.

BIN
fine-j2v8/src/main/resources/libj2v8_win32_x86.dll

Binary file not shown.

67
fine-log4j/src/main/java/com/fr/third/apache/log4j/DailyRollingFileAppender.java

@ -24,6 +24,7 @@ import com.fr.third.apache.log4j.spi.LoggingEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.text.SimpleDateFormat;
@ -302,7 +303,7 @@ public class DailyRollingFileAppender extends FileAppender {
}
/**
Rollover the current file to a new file.
* Rollover the current file to a new file.
*/
void rollOver() throws IOException {
@ -312,7 +313,7 @@ public class DailyRollingFileAppender extends FileAppender {
return;
}
String datedFilename = fileName+sdf.format(now)+COMPRESS_SUFFIX;
String datedFilename = fileName + sdf.format(now) + COMPRESS_SUFFIX;
// It is too early to roll over because we are still within the
// bounds of the current interval. Rollover will occur once the
// next interval is reached.
@ -329,51 +330,67 @@ public class DailyRollingFileAppender extends FileAppender {
}
File file = new File(fileName);
boolean result = false;
boolean isGzipSuccess = false;
FileInputStream fis = null;
FileOutputStream fos = null;
GZIPOutputStream gzos = null;
try {
fis = new FileInputStream(file);
fos = new FileOutputStream(target);
gzos = new GZIPOutputStream(fos);
try (FileInputStream fis = new FileInputStream(file);
FileOutputStream fos = new FileOutputStream(target);
GZIPOutputStream gzos = new GZIPOutputStream(fos);) {
byte[] inbuf = new byte[8102];
int n;
while ((n = fis.read(inbuf)) != -1) {
gzos.write(inbuf, 0, n);
}
result = true;
} catch (Exception e){
isGzipSuccess = true;
} catch (Exception e) {
LogLog.error("Compress " + fileName + " to " + scheduledFilename + " failed.");
LogLog.error(e.getMessage(), e);
} finally {
if(gzos!=null) {
gzos.close();
}
if (fis != null) {
fis.close();
}
}
if(result) {
file.delete();
LogLog.debug(fileName +" -> "+ scheduledFilename);
boolean isDeleteSuccess = true;
if (isGzipSuccess) {
isDeleteSuccess = file.delete();
LogLog.debug(fileName + " -> " + scheduledFilename);
} else {
LogLog.error("Failed to rename ["+fileName+"] to ["+scheduledFilename+"].");
LogLog.error("Failed to rename [" + fileName + "] to [" + scheduledFilename + "].");
}
try {
// This will also close the file. This is OK since multiple
// close operations are safe.
this.setFile(fileName, true, this.bufferedIO, this.bufferSize);
} catch (IOException e) {
errorHandler.error("setFile(" + fileName + ", true) call failed.");
}
if(!isDeleteSuccess){
synchronized (this) {
if (scheduledFilename.equals(datedFilename)) {
return;
}
catch(IOException e) {
errorHandler.error("setFile("+fileName+", true) call failed.");
LogLog.debug("file delete failed, empty it.");
emptyFile(file);
scheduledFilename = datedFilename;
}
}else {
scheduledFilename = datedFilename;
}
}
/**
* @param file empty file
*/
private static void emptyFile(File file) {
try(FileWriter fileWriter = new FileWriter(file)) {
if (!file.exists()) {
file.createNewFile();
}
fileWriter.write("");
fileWriter.flush();
} catch (IOException e) {
LogLog.debug("empty file failed:" + e.getMessage() + e);
}
}
/**
* This method differentiates DailyRollingFileAppender from its

Loading…
Cancel
Save