-
Notifications
You must be signed in to change notification settings - Fork 190
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
Aishwarya Jagarapu
committed
Mar 7, 2025
1 parent
0aff5c4
commit ac58c18
Showing
41 changed files
with
5,355 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
### IntelliJ IDEA ### | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store | ||
|
||
### Maven ### | ||
target/ | ||
|
||
### Log4J ### | ||
*.log |
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,28 @@ | ||
# Java PRT | ||
|
||
This project is the Java runtime for executing monitors compiled by the P Java | ||
backend. It reimplements a subset of the Coyote state machine runtime. | ||
|
||
## Building | ||
|
||
``` | ||
$ mvn compile | ||
``` | ||
|
||
## Testing | ||
|
||
``` | ||
$ mvn test | ||
``` | ||
|
||
## Installation | ||
|
||
This builds and places the compiled JAR in your local Maven repository, which | ||
by default is located at `~/.m2/`. | ||
|
||
``` | ||
$ mvn install | ||
... | ||
[INFO] Installing target/PJavaRuntime-1.0-SNAPSHOT.jar to /Users/nathta/.m2/repository/p/runtime/PJavaRuntime/1.0-SNAPSHOT/PJavaRuntime-1.0-SNAPSHOT.jar | ||
[INFO] Installing pom.xml to /Users/nathta/.m2/repository/p/runtime/PJavaRuntime/1.0-SNAPSHOT/PJavaRuntime-1.0-SNAPSHOT.pom | ||
``` |
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,81 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>p.runtime</groupId> | ||
<artifactId>PJavaRuntime</artifactId> | ||
<version>${revision}</version> | ||
|
||
<name>Java runtime for the P programming language</name> | ||
<url>https://github.com/p-org/P</url> | ||
|
||
<licenses> | ||
<license> | ||
<name>MIT License</name> | ||
<url>https://spdx.org/licenses/MIT.html</url> | ||
</license> | ||
</licenses> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<version>5.8.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-api</artifactId> | ||
<version>2.17.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core</artifactId> | ||
<version>2.17.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-layout-template-json</artifactId> | ||
<version>2.17.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<version>0.8.8</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<version>0.8.8</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>prepare-agent</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>report</id> | ||
<phase>test</phase> | ||
<goals> | ||
<goal>report</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<log4j2.configurationFile>${project.basedir}/src/main/resources/log4j2.xml</log4j2.configurationFile> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<revision>1.0-SNAPSHOT</revision> | ||
</properties> | ||
|
||
</project> |
172 changes: 172 additions & 0 deletions
172
Src/PRuntimes/PJavaRuntime/src/main/java/parsers/PTraceParserUtils.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,172 @@ | ||
package parsers; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Stream; | ||
|
||
public class PTraceParserUtils { | ||
private static final String PREFIX = "<SendLog>"; | ||
|
||
private static final String evtRegex = "sent event '(\\w+) with payload \\((.+)\\)' to"; | ||
public static final Pattern evtPattern = Pattern.compile(evtRegex); | ||
|
||
private static boolean sendLogFilter(String msg) { | ||
return msg.startsWith(PREFIX); | ||
} | ||
|
||
/** | ||
* Produces the given stream of log lines, removing the ones that do | ||
* not originate from the SendLog source. | ||
* @param s | ||
* @return | ||
*/ | ||
public static Stream<String> FilterSendLogs(Stream<String> s){ | ||
return s.filter(PTraceParserUtils::sendLogFilter); | ||
} | ||
|
||
|
||
/** | ||
* These routines help convert serialised data in the form emitted by the C# runtime, | ||
* which all inherit from `PLang.CSharpRuntime.PrtType`. Should any PrtType's `.toString()` | ||
* method be changed, these conversion functions may break. | ||
*/ | ||
public static class Conversions { | ||
private static final String tupleDelimiter = ","; /* Note the lack of space, vis a vis named tuples */ | ||
private static final String namedTupleDelimiter = ", "; | ||
|
||
/** | ||
* Given a serialized named tuple of the form `<k1:v1, k2:v2, ... kn:vn, >`, return an array | ||
* of Strings containing all the key-value pairs. (Note the trailing ", " after the final | ||
* key-value pair[1]; the suprious empty final element is truncated from the final result array.) | ||
* | ||
* [1]: https://github.com/p-org/P/blob/master/Src/PRuntimes/PCSharpRuntime/Values/PrtTuple.cs#L191-L191 | ||
* @param token The string representation of a k-ary named tuple | ||
* @return An array of `k` elements, containing each of the colon-delimited key-value pairs. | ||
*/ | ||
public static List<String> namedTupleToKVPairs(String token) { | ||
if (token.charAt(0) != '<' || !token.endsWith(", >")) { | ||
throw new RuntimeException(String.format("Token \"%s\" does not appear to be a named tuple?", token)); | ||
} | ||
token = token.substring(1, token.length() - 3); // Eat the open brace and trailing comma/space/closing brace. | ||
return splitCommasOutsideStrings(token, ", "); | ||
} | ||
|
||
/** | ||
* Given a serialised tuple of the form `<v1,v2,v3...vn,>`, return an array of Strings | ||
* containing all the values. (Notice the trailing "," after the final value[1]; this spurious | ||
* element is truncated from the final result.) | ||
* | ||
* [1]: https://github.com/p-org/P/blob/master/Src/PRuntimes/PCSharpRuntime/Values/PrtTuple.cs#L95-L95 | ||
* @param token | ||
* @return | ||
*/ | ||
public static List<String> tupleToValues(String token) { | ||
if (token.charAt(0) != '<' || !token.endsWith(",>")) { | ||
throw new RuntimeException(String.format("Token \"%s\" does not appear to be a tuple?", token)); | ||
} | ||
token = token.substring(1, token.length() - 2); // Eat the open brace and trailing comma/closing brace | ||
return splitCommasOutsideStrings(token, ","); | ||
} | ||
|
||
/** | ||
* Given a key-value pair of the form "key:value", where value | ||
* is an Integer, extract the int. | ||
* @param kv | ||
* @return | ||
*/ | ||
public static int kvPairToInt(String kv) { | ||
return Integer.valueOf(kv.split(":")[1]); | ||
} | ||
|
||
/** | ||
* Given a key-value pair of the form "key:value", where value | ||
* is a long, extract the long. | ||
* @param kv | ||
* @return | ||
*/ | ||
public static long kvPairToLong(String kv) { | ||
return Long.valueOf(kv.split(":")[1]); | ||
} | ||
|
||
/** | ||
* Given a key-value pair of the form "key:MachineName(value)", where value | ||
* is a long and MachineName is an arbitrary identifier, extract the long. | ||
* @param kv | ||
* @return | ||
*/ | ||
public static long kvPairToMachineId(String kv) { | ||
int openParen = kv.indexOf("("); | ||
int closeParen = kv.indexOf(")"); | ||
return Long.valueOf(kv.substring(openParen + 1, closeParen)); | ||
} | ||
|
||
/** | ||
* Given a key-value pair of the form "key:value", where value | ||
* is a float, extract the long. | ||
* @param kv | ||
* @return | ||
*/ | ||
public static float kvPairToFloat(String kv) { | ||
return Float.valueOf(kv.split(":")[1]); | ||
} | ||
|
||
/** | ||
* Given a key-value pair of the form "key:value", where value | ||
* is an enumerated value, extract it. | ||
*/ | ||
public static int kvPairToEnumVal(String kv) { | ||
// Internally, the integer representation will already have been written out, | ||
// so this is equivalent to parsing an int out. | ||
return kvPairToInt(kv); | ||
} | ||
|
||
/** | ||
* Splits `s` according to its occurrences of `delimiter`, such that the delimiters | ||
* do not fall inside a quoted string. This method assumes that there are no dangling | ||
* quotes (i.e. there are an even number of occurrences of /[^\\]"/ in s. | ||
* | ||
* @param s | ||
* @return | ||
*/ | ||
private static List<String> splitCommasOutsideStrings(String str, String delimiter) | ||
{ | ||
ArrayList<String> ret = new ArrayList<>(); | ||
boolean inQuotedString = (str.charAt(0) == '"'); | ||
|
||
StringBuilder currentStr = new StringBuilder(str.substring(0, 1)); | ||
|
||
// Note the slightly-pedestrian way of writing this. The alternative was to write | ||
// a gnarly regex using negative lookahead assertions (which would be O(n^2) anyway) | ||
// or taking a major dependency on something like Apache Commons. | ||
for (int i = 1; i < str.length(); i++) { | ||
if (!inQuotedString && str.substring(i).startsWith(delimiter)) { | ||
ret.add(currentStr.toString()); | ||
currentStr = new StringBuilder(); | ||
i += delimiter.length() - 1; | ||
continue; | ||
} | ||
|
||
char prev = str.charAt(i - 1); | ||
char curr = str.charAt(i); | ||
|
||
if (curr == '"' && prev != '\\') { | ||
inQuotedString = !inQuotedString; | ||
} | ||
currentStr.append(curr); | ||
} | ||
if (currentStr.length() > 0) { | ||
ret.add(currentStr.toString()); | ||
} | ||
return ret; | ||
} | ||
|
||
/** | ||
* Given a key-value pair of the form "key:value", where value is a string, extract it. | ||
* Note: https://github.com/p-org/P/issues/447 is an issue here. | ||
*/ | ||
public static String kvPairToString(String kv) { | ||
return kv.split(":", 2)[1]; | ||
} | ||
} | ||
} |
Oops, something went wrong.