Skip to content

Commit

Permalink
Adding the Idle Micro Benchmark into the openj9-systemtest repo.
Browse files Browse the repository at this point in the history
The Idle Micro Benchmark has been written to test the Idle Tuning feature and its proper working.
This test needs to be committed into the openj9-systemtest repo as a stress test.

Signed-off-by: Tanvi Kini [email protected]
  • Loading branch information
tanvikini committed Nov 29, 2017
1 parent b08e1c5 commit 25d59cc
Show file tree
Hide file tree
Showing 13 changed files with 695 additions and 0 deletions.
109 changes: 109 additions & 0 deletions openj9.test.idle/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0"?>
<!--
Copyright (c) 2017 IBM Corp.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which accompanies this distribution
and is available at http://eclipse.org/legal/epl-2.0 or the Apache License,
Version 2.0 which accompanies this distribution and is available at
https://www.apache.org/licenses/LICENSE-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception [1] and GNU General Public License,
version 2 with the OpenJDK Assembly Exception [2].
[1] https://www.gnu.org/software/classpath/license.html
[2] http://openjdk.java.net/legal/assembly-exception.html
SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
-->

<project name="openj9.test.daa" default="build">

<!-- Set default for source_root. -->
<property name="source_root" location="../"/>

<!-- Set default for STF location. -->
<!-- Assumes source repositories are checked out under a common root - e.g. and the repository
has been built in-situ - i.e.
stf repository: /home/userid/git/stf
java.svt repository: /home/userid/git/java.svt
If the stf repository has been cloned or built to a different location, the stf_root property
must be set on the command line - e.g. -Dstf_root=/my_stf_build_dir
-->
<property name="stf_root" location="${source_root}/../stf"/>

<!-- Import settings used by multiple projects. -->
<import file="${source_root}/openj9.build/include/top.xml"/>

<!-- For modularity you need a directory above the package structure to hold the module.java file -->
<property name="module" value="test.idle" />
<property name="src_dir" value="src/${module}" />
<property name="bin_dir" value="bin" />

<property name="jar_file" value="${bin_dir}/${module}.jar" />

<!-- We need junit and stf to compile this project. -->
<path id="project.class.path">
<path refid="junit.class.path" />
<path refid="stf.class.path" />
</path>

<!-- Projects which need to be built before this one. -->
<!-- dir must be set on the ant task otherwise the basedir property is not set to a new value in the subant task. -->
<target name="build-dependencies">
<!-- <ant antfile="${stf_root}/stf.build/build.xml" dir="${stf_root}/stf.build" inheritAll="false"/> -->
</target>

<target name="build" depends="build-no-natives, build-natives">
</target>

<target name="build-no-natives" depends="build-dependencies, check-prereqs, build-archives">
</target>

<target name="build-natives">
</target>

<target name="build-archives" depends="build-jar">
</target>

<target name="build-jar" depends="build-java, create-bin-dir">
<jar destfile="${jar_file}">
<fileset dir="${bin_dir}" includes="**/*.class" />
</jar>
</target>

<target name="build-java" depends="check-prereqs, create-bin-dir">
<!--
The Ant javac task only checks time dependencies between .java files and their .class files,
so fails to recompile in situations such as the signatures of a dependent method changing.
The depend target checks the dependencies and deletes any .class files older than the files
which depend on them, thereby ensuring recompilation.
-->
<depend srcdir="${src_dir}" destdir="${bin_dir}" classpathref="project.class.path">
<include name="**/*.java"/>
</depend>
<javac srcdir="${src_dir}"
destdir="${bin_dir}"
fork="true"
executable="${java8_compiler}"
debug="true"
classpathref="project.class.path"
encoding="UTF-8"
includeantruntime="false"
failonerror="true">
<include name="**/*.java"/>
</javac>
</target>

<target name="create-bin-dir">
<mkdir dir="${bin_dir}"/>
</target>

<target name="clean">
<delete dir="${bin_dir}"/>
</target>

</project>
159 changes: 159 additions & 0 deletions openj9.test.idle/src/test.idle/net/openj9/test/CombinedLoad.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*******************************************************************************
* Copyright (c) 2017 IBM Corp.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which accompanies this distribution
* and is available at http://eclipse.org/legal/epl-2.0 or the Apache License,
* Version 2.0 which accompanies this distribution and is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public License,
* version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*******************************************************************************/
package net.openj9.test;

import java.io.File;
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.Callable;
import java.util.Calendar;
import java.util.Date;
import java.awt.image.BufferedImage;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import javax.imageio.ImageIO;
import java.lang.management.ManagementFactory;

import net.adoptopenjdk.test.gc.idlemicrobenchmark.LargeObj;


public class CombinedLoad implements Callable<Long>
{
private int workloadImageNumber;
private long threadId;
private long busyTime = 0;
private long memoryLimitInBytes = 0L;
private final int numObjs = 10000;
private long numtrans = 0;

public CombinedLoad(int workloadTypeNum, long mSec, long memLimitInBytes) {
workloadImageNumber = workloadTypeNum;
busyTime = mSec * 1000000L ;
memoryLimitInBytes = memLimitInBytes;
}

public long getTrans() {
return numtrans;
}

public void resetTrans() {
numtrans = 0;
}

public long getThreadId() {
return threadId;
}

public Long call() {
Date dateobj;
Calendar calobj;
long startTime = 0;
long currTime = 0;
float diff = 0;
LargeObj[] memoryFill = new LargeObj[numObjs];
DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
java.lang.management.MemoryMXBean membean = ManagementFactory.getMemoryMXBean();
long heapInBytes = 0L;

threadId = Thread.currentThread().getId();
startTime = System.nanoTime();
System.out.println("Test Application: CPU: Thread: " + threadId + " busy looping start");
do {
File iFile;
BufferedImage image;

if ( System.getProperty("isIdle").equals("true") ) {
System.out.println("App is going IDLE.. Stop working.. zzzzzz");
break;
}

// This loop tries to wake up JIT by running for 30 secs
long busyTime = 30000 * 1000000L;
while ((System.nanoTime() - startTime) < busyTime) {
Random rand = new Random();
double result = java.lang.Math.log(rand.nextDouble());
}

for (int i = 0; i < 10000 ; i++) {

dateobj = new Date();
calobj = Calendar.getInstance();
currTime = System.nanoTime();
diff = (float) ((float) (currTime - startTime) / (float) 1000000);
for (int j = 0; j < numObjs; j++) {
memoryFill[j] = new LargeObj(diff);
}

if (diff == 1.000000 || diff == 2.000000 || diff == 3.000000 || diff == 4.000000 || diff == 5.000000) {
System.out.println("CurrTime: " + currTime + " startTime: " + startTime + " busyTime: " + busyTime + " diff: " + diff);
}
if (diff > 6) {
break;
}
}

try {
if( System.getProperty("isIdle").equals("true") ) {
System.out.println("App is going IDLE.. Stop working.. zzzzzz");
break;
}
switch(workloadImageNumber) {
case 0:
iFile = new File("images/Exactly1kb.jpg");
break;
case 1:
iFile = new File("images/5KbImage.jpg");
break;
case 2:
iFile = new File("images/1MbImage.jpg");
break;
case 3:
iFile = new File("images/1point5MbImage.jpg");
break;
case 4:
iFile = new File("images/2MbImage.jpg");
break;
case 5:
iFile = new File("images/5MbImage.jpg");
break;
case 6:
iFile = new File("images/15point5MbImage.png");
break;
default :
iFile = new File("images/1MbImage.jpg");
}
image = ImageIO.read(iFile);
}catch (IOException e) {
System.err.println("Error reading image file\n");
}

iFile = null;
image = null;
currTime = System.nanoTime();
numtrans++;
heapInBytes = membean.getHeapMemoryUsage().getUsed();

} while((currTime - startTime) < busyTime && heapInBytes <= memoryLimitInBytes);

System.out.println("Test Application: Thread: " + threadId + " busy looping done; Num-trans: " + numtrans);
return threadId;
}
}
Loading

0 comments on commit 25d59cc

Please sign in to comment.