Browse Source

Merge pull request #1431 in CORE/base-third from final/10.0 to persist/10.0

* commit '5e431502db437166d7853cfcbd2999b5c63184ae':
  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无法分割
persist/10.0 10.0.12.2020.12.17
superman 4 years ago
parent
commit
19d50d33b8
  1. 7
      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. 139
      fine-log4j/src/main/java/com/fr/third/apache/log4j/DailyRollingFileAppender.java

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

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

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.Map;
import java.util.Set; import java.util.Set;
import com.eclipsesource.v8.inspector.V8InspectorDelegate;
import com.eclipsesource.v8.utils.V8Executor; import com.eclipsesource.v8.utils.V8Executor;
import com.eclipsesource.v8.utils.V8Map; import com.eclipsesource.v8.utils.V8Map;
import com.eclipsesource.v8.utils.V8Runnable; import com.eclipsesource.v8.utils.V8Runnable;
@ -47,6 +48,7 @@ public class V8 extends V8Object {
private Map<String, Object> data = null; private Map<String, Object> data = null;
private final V8Locker locker; private final V8Locker locker;
private SignatureProvider signatureProvider = null;
private long objectReferences = 0; private long objectReferences = 0;
private long v8RuntimePtr = 0; private long v8RuntimePtr = 0;
private List<Releasable> resources = null; private List<Releasable> resources = null;
@ -162,6 +164,10 @@ public class V8 extends V8Object {
return runtime; return runtime;
} }
public void setSignatureProvider(final SignatureProvider signatureProvider) {
this.signatureProvider = signatureProvider;
}
/** /**
* Adds a ReferenceHandler to track when new V8Objects are created. * Adds a ReferenceHandler to track when new V8Objects are created.
* *
@ -276,6 +282,20 @@ public class V8 extends V8Object {
objectHandle = _getGlobalObject(v8RuntimePtr); 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. * Returns an UNDEFINED constant.
* *
@ -670,16 +690,51 @@ public class V8 extends V8Object {
* Primitives will be boxed. * Primitives will be boxed.
* *
* @param script The script to execute. * @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 * @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. * 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. * @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(); checkThread();
checkScript(script); 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. * @return The unique build ID of the Native library.
*/ */
public long getBuildID() { public static long getBuildID() {
return _getBuildID(); return _getBuildID();
} }
@ -1321,6 +1376,10 @@ public class V8 extends V8Object {
_addArrayNullItem(v8RuntimePtr, arrayHandle); _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) { protected int getType(final long v8RuntimePtr, final long objectHandle) {
return _getType(v8RuntimePtr, objectHandle); return _getType(v8RuntimePtr, objectHandle);
} }
@ -1409,6 +1468,12 @@ public class V8 extends V8Object {
private native long _createIsolate(String globalAlias); 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 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); 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 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);
private native int _getType(long v8RuntimePtr, long objectHandle, final int index, final int length); 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 _getGlobalObject(final long v8RuntimePtr);
private native long _getBuildID(); private native static long _getBuildID();
private native static void _startNodeJS(final long v8RuntimePtr, final String fileName); 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. * 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) { if (scriptResult instanceof Releasable) {
((Releasable) scriptResult).release(); ((Releasable) scriptResult).release();
} }
if (scriptResult instanceof Releasable) {
((Releasable) scriptResult).release();
}
} }
while (!forceTerminating && longRunning) { while (!forceTerminating && longRunning) {
synchronized (this) { 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.

139
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.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -301,79 +302,95 @@ public class DailyRollingFileAppender extends FileAppender {
return TOP_OF_TROUBLE; // Deliberately head for trouble... return TOP_OF_TROUBLE; // Deliberately head for trouble...
} }
/** /**
Rollover the current file to a new file. * Rollover the current file to a new file.
*/ */
void rollOver() throws IOException { void rollOver() throws IOException {
/* Compute filename, but only if datePattern is specified */ /* Compute filename, but only if datePattern is specified */
if (datePattern == null) { if (datePattern == null) {
errorHandler.error("Missing DatePattern option in rollOver()."); errorHandler.error("Missing DatePattern option in rollOver().");
return; 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 // It is too early to roll over because we are still within the
// bounds of the current interval. Rollover will occur once the // bounds of the current interval. Rollover will occur once the
// next interval is reached. // next interval is reached.
if (scheduledFilename.equals(datedFilename)) { if (scheduledFilename.equals(datedFilename)) {
return; return;
} }
// close current file, and compress it to datedFilename // close current file, and compress it to datedFilename
this.closeFile(); this.closeFile();
File target = new File(scheduledFilename); File target = new File(scheduledFilename);
if (target.exists()) { if (target.exists()) {
target.delete(); target.delete();
} }
File file = new File(fileName); File file = new File(fileName);
boolean result = false; boolean isGzipSuccess = false;
FileInputStream fis = null; try (FileInputStream fis = new FileInputStream(file);
FileOutputStream fos = null; FileOutputStream fos = new FileOutputStream(target);
GZIPOutputStream gzos = null; GZIPOutputStream gzos = new GZIPOutputStream(fos);) {
try { byte[] inbuf = new byte[8102];
fis = new FileInputStream(file); int n;
fos = new FileOutputStream(target);
gzos = new GZIPOutputStream(fos); while ((n = fis.read(inbuf)) != -1) {
byte[] inbuf = new byte[8102]; gzos.write(inbuf, 0, n);
int n; }
isGzipSuccess = true;
while ((n = fis.read(inbuf)) != -1) { } catch (Exception e) {
gzos.write(inbuf, 0, n); LogLog.error("Compress " + fileName + " to " + scheduledFilename + " failed.");
LogLog.error(e.getMessage(), e);
} }
result = true;
} catch (Exception e){ boolean isDeleteSuccess = true;
LogLog.error("Compress " + fileName + " to " + scheduledFilename + " failed."); if (isGzipSuccess) {
LogLog.error(e.getMessage(), e); isDeleteSuccess = file.delete();
} finally { LogLog.debug(fileName + " -> " + scheduledFilename);
if(gzos!=null) { } else {
gzos.close(); 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 (fis != null) { if(!isDeleteSuccess){
fis.close(); synchronized (this) {
if (scheduledFilename.equals(datedFilename)) {
return;
}
LogLog.debug("file delete failed, empty it.");
emptyFile(file);
scheduledFilename = datedFilename;
}
}else {
scheduledFilename = datedFilename;
} }
} }
if(result) {
file.delete();
LogLog.debug(fileName +" -> "+ scheduledFilename);
} else {
LogLog.error("Failed to rename ["+fileName+"] to ["+scheduledFilename+"].");
}
try { /**
// This will also close the file. This is OK since multiple * @param file empty file
// close operations are safe. */
this.setFile(fileName, true, this.bufferedIO, this.bufferSize); private static void emptyFile(File file) {
} try(FileWriter fileWriter = new FileWriter(file)) {
catch(IOException e) { if (!file.exists()) {
errorHandler.error("setFile("+fileName+", true) call failed."); file.createNewFile();
}
fileWriter.write("");
fileWriter.flush();
} catch (IOException e) {
LogLog.debug("empty file failed:" + e.getMessage() + e);
}
} }
scheduledFilename = datedFilename;
}
/** /**
* This method differentiates DailyRollingFileAppender from its * This method differentiates DailyRollingFileAppender from its

Loading…
Cancel
Save