Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SecurityManager #79

Closed
wants to merge 9 commits into from
14 changes: 9 additions & 5 deletions HyperAlloc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@

<properties>
<jacoco.version>0.8.5</jacoco.version>
<jdk.version>8</jdk.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.testSource>1.8</maven.compiler.testSource>
<maven.compiler.testTarget>1.8</maven.compiler.testTarget>
<jdk.version>17</jdk.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.testSource>17</maven.compiler.testSource>
<maven.compiler.testTarget>17</maven.compiler.testTarget>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<surefire-plugin.version>2.22.1</surefire-plugin.version>
Expand Down Expand Up @@ -385,6 +385,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>15</source>
<target>15</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ public final class HyperAlloc {
private HyperAlloc() {}

public static void main(String[] args) {
try {
runner(args);
} catch (Throwable t) {
System.out.println(t.getMessage());
System.exit(1);
}
}

switch (findRunType(args)) {
case "simple" :
new SimpleRunner(new SimpleRunConfig(args)).start();
break;
default:
System.out.println("Current supported run type (-u): simple.");
System.exit(1);
static void runner(String[] args) {
try {
String runType = findRunType(args);

switch (runType) {
case "simple":
new SimpleRunner(new SimpleRunConfig(args)).start();
break;
default:
throw new IllegalArgumentException(String.format("Unknown run type (-u %s), supported type is -u simple.", runType));
}
} catch (IllegalArgumentException iae) {
throw iae;
} catch (Throwable t) {
throw new RuntimeException(t);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public SimpleRunConfig(final String[] args) {
} else if (args[i].equals("-z")) {
allocationSmoothnessFactor = Double.parseDouble(args[++i]);
if (allocationSmoothnessFactor < 0 || allocationSmoothnessFactor > 1.0) {
usage();
System.exit(1);
throw new IllegalArgumentException(String.format("AllocationSmoothness of %s not in range\n",allocationSmoothnessFactor) + usage());
}
} else if (args[i].equals("-l")) {
logFile = args[++i];
Expand All @@ -77,19 +76,13 @@ public SimpleRunConfig(final String[] args) {
} else if (args[i].equals("-p") || args[i].equals("--ramp-up-seconds")) {
rampUpSeconds = Double.parseDouble(args[++i]);
} else {
usage();
System.exit(1);
throw new IllegalArgumentException(String.format("Unrecognized argument: %s\n",args[i]) + usage());
}
}
}

private void usage() {
System.out.println("Usage: java -jar HyperAlloc.jar " +
"[-u run type] [-a allocRateInMb] [-s longLivedObjectsInMb] " +
"[-m midAgedObjectsInMb] [-d runDurationInSeconds ] [-t numOfThreads] [-n minObjectSize] " +
"[-x maxObjectSize] [-r pruneRatio] [-f reshuffleRatio] " +
"[-l outputFile] [-b|-allocation-log logFile] [-z allocationSmoothness (0 to 1.0)] " +
"[-p rampUpSeconds ]");
private String usage() {
return "Usage: java -jar HyperAlloc.jar [-u run type] [-a allocRateInMb] [-s longLivedObjectsInMb] [-m midAgedObjectsInMb] [-d runDurationInSeconds ] [-t numOfThreads] [-n minObjectSize] [-x maxObjectSize] [-r pruneRatio] [-f reshuffleRatio] [-l outputFile] [-b|-allocation-log logFile] [-z allocationSmoothness (0 to 1.0)] [-p rampUpSeconds ]";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
package com.amazon.corretto.benchmark.hyperalloc;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

import org.junit.jupiter.api.Test;

import static com.github.stefanbirkner.systemlambda.SystemLambda.catchSystemExit;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.*;

class HyperAllocTest {

Expand All @@ -21,9 +19,11 @@ void DefaultRunTypeTest() {
}

@Test
void UnknownRunTypeTest() throws Exception {
int status = catchSystemExit(
() -> HyperAlloc.main(new String[]{"-u", "unknown", "-a", "5"}));
assertThat(status, is(1));
void UnknownRunTypeTest() {
Exception e = assertThrows(IllegalArgumentException.class, () -> {
HyperAlloc.runner(new String[]{"-u", "unknown", "-a", "5"});
});
String expected = "Unknown run type (-u unknown), supported type is -u simple.";
assertEquals(expected,e.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
package com.amazon.corretto.benchmark.hyperalloc;

import com.sun.management.HotSpotDiagnosticMXBean;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.lang.management.ManagementFactory;

import static com.github.stefanbirkner.systemlambda.SystemLambda.catchSystemExit;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -84,10 +81,14 @@ void StringArgsTest() {
}

@Test
void UnknownParameterShouldExitTest() throws Exception {
int status = catchSystemExit(
() -> new SimpleRunConfig(new String[]{"-w", "who"}));
assertThat(status, is(1));
void UnknownParameterShouldExitTest() {
Exception e = assertThrows(IllegalArgumentException.class, () -> {
HyperAlloc.runner(new String[]{"-w", "who"});
});

String expected = "Unrecognized argument: -w\n" +
"Usage: java -jar HyperAlloc.jar [-u run type] [-a allocRateInMb] [-s longLivedObjectsInMb] [-m midAgedObjectsInMb] [-d runDurationInSeconds ] [-t numOfThreads] [-n minObjectSize] [-x maxObjectSize] [-r pruneRatio] [-f reshuffleRatio] [-l outputFile] [-b|-allocation-log logFile] [-z allocationSmoothness (0 to 1.0)] [-p rampUpSeconds ]";
assertEquals(expected,e.getMessage());
}

class MySecurityManager extends SecurityManager {}
Expand Down