mirror of
https://github.com/Qortal/AT.git
synced 2025-02-11 17:55:52 +00:00
Convert logging to lambda-based to reduce CPU load if logging disabled, also bump to v1.3.6 as interface changed
This commit is contained in:
parent
2b28cbe07b
commit
facb9c213f
@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.ciyam</groupId>
|
<groupId>org.ciyam</groupId>
|
||||||
<artifactId>AT</artifactId>
|
<artifactId>AT</artifactId>
|
||||||
<version>1.3.5</version>
|
<version>1.3.6</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<properties>
|
<properties>
|
||||||
<skipTests>true</skipTests>
|
<skipTests>true</skipTests>
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
package org.ciyam.at;
|
package org.ciyam.at;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public interface AtLogger {
|
public interface AtLogger {
|
||||||
|
|
||||||
void error(final String message);
|
void error(final String message);
|
||||||
|
|
||||||
|
void error(final Supplier<String> messageSupplier);
|
||||||
|
|
||||||
void debug(final String message);
|
void debug(final String message);
|
||||||
|
|
||||||
|
void debug(final Supplier<String> messageSupplier);
|
||||||
|
|
||||||
void echo(final String message);
|
void echo(final String message);
|
||||||
|
|
||||||
|
void echo(final Supplier<String> messageSupplier);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1068,7 +1068,7 @@ public enum FunctionCode {
|
|||||||
if (functionData.paramCount == 2 && functionData.value2 == null)
|
if (functionData.paramCount == 2 && functionData.value2 == null)
|
||||||
throw new IllegalFunctionCodeException("Passed value2 is null but function has paramCount of (" + this.paramCount + ")");
|
throw new IllegalFunctionCodeException("Passed value2 is null but function has paramCount of (" + this.paramCount + ")");
|
||||||
|
|
||||||
state.getLogger().debug("Function \"" + this.name() + "\"");
|
state.getLogger().debug(() -> String.format("Function \"%s\"", this.name()));
|
||||||
|
|
||||||
postCheckExecute(functionData, state, rawFunctionCode);
|
postCheckExecute(functionData, state, rawFunctionCode);
|
||||||
}
|
}
|
||||||
|
@ -675,18 +675,17 @@ public class MachineState {
|
|||||||
|
|
||||||
// Pre-execution checks
|
// Pre-execution checks
|
||||||
if (this.isFinished) {
|
if (this.isFinished) {
|
||||||
logger.debug("Not executing as already finished!");
|
logger.debug(() -> "Not executing as already finished!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isFrozen && this.currentBalance <= this.frozenBalance) {
|
if (this.isFrozen && this.currentBalance <= this.frozenBalance) {
|
||||||
logger.debug("Not executing as current balance [" + this.currentBalance + "] hasn't increased since being frozen at [" + this.frozenBalance + "]");
|
logger.debug(() -> String.format("Not executing as current balance [%d] hasn't increased since being frozen at [%d]", this.currentBalance, this.frozenBalance));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isSleeping && this.sleepUntilHeight != null && this.currentBlockHeight < this.sleepUntilHeight) {
|
if (this.isSleeping && this.sleepUntilHeight != null && this.currentBlockHeight < this.sleepUntilHeight) {
|
||||||
logger.debug("Not executing as current block height [" + this.currentBlockHeight + "] hasn't reached sleep-until block height ["
|
logger.debug(() -> String.format("Not executing as current block height [%d] hasn't reached sleep-until block height [%d]", this.currentBlockHeight, this.sleepUntilHeight));
|
||||||
+ this.sleepUntilHeight + "]");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -716,21 +715,21 @@ public class MachineState {
|
|||||||
if (nextOpCode == null)
|
if (nextOpCode == null)
|
||||||
throw new IllegalOperationException("OpCode 0x" + String.format("%02x", rawOpCode) + " not recognised");
|
throw new IllegalOperationException("OpCode 0x" + String.format("%02x", rawOpCode) + " not recognised");
|
||||||
|
|
||||||
this.logger.debug("[PC: " + String.format("%04x", this.programCounter) + "] " + nextOpCode.name());
|
this.logger.debug(() -> String.format("[PC: %04x] %s", this.programCounter, nextOpCode.name()));
|
||||||
|
|
||||||
// Request opcode step-fee from API, apply fee to balance, etc.
|
// Request opcode step-fee from API, apply fee to balance, etc.
|
||||||
int opcodeSteps = this.api.getOpCodeSteps(nextOpCode);
|
int opcodeSteps = this.api.getOpCodeSteps(nextOpCode);
|
||||||
long opcodeFee = opcodeSteps * feePerStep;
|
long opcodeFee = opcodeSteps * feePerStep;
|
||||||
|
|
||||||
if (this.steps + opcodeSteps > maxSteps) {
|
if (this.steps + opcodeSteps > maxSteps) {
|
||||||
logger.debug("Enforced sleep due to exceeding maximum number of steps (" + maxSteps + ") per execution round");
|
logger.debug(() -> String.format("Enforced sleep due to exceeding maximum number of steps (%d) per execution round", maxSteps));
|
||||||
this.isSleeping = true;
|
this.isSleeping = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.currentBalance < opcodeFee) {
|
if (this.currentBalance < opcodeFee) {
|
||||||
// Not enough balance left to continue execution - freeze AT
|
// Not enough balance left to continue execution - freeze AT
|
||||||
logger.debug("Frozen due to lack of balance");
|
logger.debug(() -> "Frozen due to lack of balance");
|
||||||
this.isFrozen = true;
|
this.isFrozen = true;
|
||||||
this.frozenBalance = this.currentBalance;
|
this.frozenBalance = this.currentBalance;
|
||||||
break;
|
break;
|
||||||
@ -746,7 +745,7 @@ public class MachineState {
|
|||||||
// Synchronize programCounter with codeByteBuffer in case of JMPs, branches, etc.
|
// Synchronize programCounter with codeByteBuffer in case of JMPs, branches, etc.
|
||||||
this.programCounter = codeByteBuffer.position();
|
this.programCounter = codeByteBuffer.position();
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
this.logger.debug("Error at PC " + String.format("%04x", this.programCounter) + ": " + e.getMessage());
|
this.logger.error(() -> String.format("Error at PC %04x: %s", this.programCounter, e.getMessage()));
|
||||||
|
|
||||||
if (this.onErrorAddress == null) {
|
if (this.onErrorAddress == null) {
|
||||||
this.isFinished = true;
|
this.isFinished = true;
|
||||||
@ -767,18 +766,18 @@ public class MachineState {
|
|||||||
|
|
||||||
if (this.isSleeping) {
|
if (this.isSleeping) {
|
||||||
if (this.sleepUntilHeight != null)
|
if (this.sleepUntilHeight != null)
|
||||||
this.logger.debug("Sleeping until block " + this.sleepUntilHeight);
|
this.logger.debug(() -> String.format("Sleeping until block %d", this.sleepUntilHeight));
|
||||||
else
|
else
|
||||||
this.logger.debug("Sleeping until next block");
|
this.logger.debug(() -> "Sleeping until next block");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isStopped) {
|
if (this.isStopped) {
|
||||||
this.logger.debug("Setting program counter to stop address: " + String.format("%04x", this.onStopAddress));
|
this.logger.debug(() -> String.format("Setting program counter to stop address: %04x", this.onStopAddress));
|
||||||
this.programCounter = this.onStopAddress;
|
this.programCounter = this.onStopAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isFinished) {
|
if (this.isFinished) {
|
||||||
this.logger.debug("Finished - refunding remaining funds back to creator");
|
this.logger.debug(() -> "Finished - refunding remaining funds back to creator");
|
||||||
this.api.onFinished(this.currentBalance, this);
|
this.api.onFinished(this.currentBalance, this);
|
||||||
this.currentBalance = 0;
|
this.currentBalance = 0;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.ciyam.at.test;
|
package org.ciyam.at.test;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.ciyam.at.AtLogger;
|
import org.ciyam.at.AtLogger;
|
||||||
|
|
||||||
public class TestLogger implements AtLogger {
|
public class TestLogger implements AtLogger {
|
||||||
@ -9,14 +11,29 @@ public class TestLogger implements AtLogger {
|
|||||||
System.err.println("ERROR: " + message);
|
System.err.println("ERROR: " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(Supplier<String> messageSupplier) {
|
||||||
|
System.err.println("ERROR: " + messageSupplier.get());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void debug(String message) {
|
public void debug(String message) {
|
||||||
System.err.println("DEBUG: " + message);
|
System.err.println("DEBUG: " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void debug(Supplier<String> messageSupplier) {
|
||||||
|
System.err.println("DEBUG: " + messageSupplier.get());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void echo(String message) {
|
public void echo(String message) {
|
||||||
System.err.println("ECHO: " + message);
|
System.err.println("ECHO: " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void echo(Supplier<String> messageSupplier) {
|
||||||
|
System.err.println("ECHO: " + messageSupplier.get());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user