RR4J is a tool that records java execution and later allows developers to replay locally.

Overview

CodeQL

RR4J [Record Replay 4 Java]

RR4J is a tool that records java execution and later allows developers to replay locally. The tool solves one of the challenges developers faces when developing an application i.e sporadic bugs which are not replicable locally or system-dependent bugs which are hard to reproduce and given a micro-service architecture being incorporated everywhere, It adds an additional overhead of setting up all the services to replicate the issue and then fix it.

Build Requirements

  1. C++ 11
  2. Java 8
  3. make
  4. maven

Building Record Agent

  1. Navigate to recordagent folder
  2. Run make all command

Building Replay Agent

  1. Navigate to replayagent folder
  2. Run make all command

Building Java code

  1. Run mvn clean install

Record Agent Configuration

Once the build is completed you need to configure the record agent, this can be done through config.json file and the file should be in the same place the agent is. Below is a sample configuration.

{
	"logFileName": "record.log",
	"logFileMaxSize": 100000,
	"maxLogFiles": 2,
	"recordDumpLocation":"",
	"delayedStart":5000,
	"recordCallerSnapshot": true,
	"blacklistPackages":["java/lang","sun/reflect","java/util", "java/io"],
	"rules": [
		{
			"method": "com/example/Test::MethodHasBug(IILjava/lang/String;)Ljava/lang/String;",
			"exception": "java.lang.NullPointerException",
			"additivity": false,
			"exitOnException": true,
			"threadsToMonitor" :1,
			"depth":2,
			"history":10,
			"threadsToRecord":10
		}
	]
}
Configurations       Usage                                                                                                                                                                                                                                                                                                                                                                                                        
logFileName           Name of the log file which will be generated
by record agent.                                                                                                                                                                                                                                                                                                                                              
logFileMaxSize       Maximum log file size in bytes                                                                                                                                                                                                                                                                                                                                                                                
maxLogFiles           Maximum log files                                                                                                                                                                                                                                                                                                                                                                                            
recordDumpLocation   Record dump location, if empty dump will be
generated in the same location agent is present.                                                                                                                                                                                                                                                                                                              
delayedStart         Delay start the record value in milliseconds                                                                                                                                                                                                                                                                                                                                                                  
recordCallerSnapshot True if you want to record 'this' object also, This
is useful when method execution updating instance variables.                                                                                                                                                                                                                                                                                          
blacklistPackages     List of packages you want to blacklist                                                                                                                                                                                                                                                                                                                                                                        
rules                 Limited feature, currently only one rule is executed.                                                                                                                                                                                                                                                                                                                                                        
method               Method name you want to record. Type : className::methodName(args)returnType
Note '.' (dot) should be replaced with '/' (slash). More info refer : https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/types.html                                                                                                                                                                      
exception             Exception if you are looking for, useful when the issue is intermittent.
Exception should be given in fully qualified java name, ex: java.lang.NullPointerException                                                                                                                                                                                                                                        
additivity           Not Implemented                                                                                                                                                                                                                                                                                                                                                                                          
exitOnException       True if you want to exit immediately after the exception is caught. Else false.                                                                                                                                                                                                                                                                                                                              
threadsToMonitor     Default is 1 Don't change the value                                                                                                                                                                                                                                                                                                                                                                      
depth                 Maximum depth you want to record.

Example :
methodA() --> Calls --↓
methodB() --> Calls --↓
methodC()

methodA() is at depth 1 and methodB() is at depth 2, methodC() is not recorded its return
value will be impersonated. This is useful if you don't bother about a particular function
at certain depth. Ex: DB call, Network Call. You are only interested in the return value.                
history               1. '0' only records one iteration which satisfies the rule
2. positive value, ex 10, 20, etc. Records the number of iteration provided.
3. A negative value, ex -10. This is like a sliding window where new records are added and previous records are discarded. This is useful
when you are looking for an exception. exitOnException must be set to true else the recording process will never be completed.  
threadsToRecord       A Total number of threads to record in a multi-threaded environment. Suppose if the system has 10 threads and the value provided is 3, Only
first 3 threads that execute the method will be allowed now and also in the future.                                                                                                                                                                                        

Example

Recording the execution

Consider a simple java code, where I want to record a methodA(long time) execution. I will configure my record agent to record 3 iterations with below config values.

"method": "Dummy::methodA(J)I",
"exception": "",
"additivity": false,
"exitOnException": false,
"threadsToMonitor" :1,
"depth":2,
"history":3,
"threadsToRecord":1
class Dummy
{
	int methodA(long time)
	{
		String sTime = String.valueOf(time);
		int val = methodB(sTime);
		return val-1;
		
	}
	
	int methodB(String s)
	{
		int x = methodC().length();
		return s.length()-x;
	}
	
	String methodC()
	{
		String x = "hello world";
		return x;
	}
	
}

public class TestClass
{

	public static void main(String[] args) 
	{
		Dummy d = new Dummy();
		for(int i=0; i<30; i++)
		{
			try {Thread.sleep(1000);} catch(Exception ex) {}
			d.methodA(System.currentTimeMillis());
		}
	}

}

Once done, Start a program with the below command.

export LD_LIBRARY_PATH=<path/to/record/agent/so/file>
java -cp recordreplay-0.0.1-SNAPSHOT-jar-with-dependencies.jar:**TestClass class file path** -agentlib:recordagent TestClass

Post this you will see a dump file generated with the name recordDump-.dmp which can be passed as input during replay mode.

Replaying the execution

Run the following command to start the tool in replay mode.

export LD_LIBRARY_PATH=<path/to/replay/agent/so/file>
java -agentlib:replayagent -cp recordreplay-0.0.1-SNAPSHOT-jar-with-dependencies.jar:**TestClass class file path** com.rr4j.replay.Replay --dumpFile recordDump.dmp

You will see an interactor, you can also add -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000 to start the debugger and attach an IDE.

To list all records use '-a' command

image

You can add a breakpoint in IDE and use '-rs recordIndex' to replay the particular record.

image

Future scope

  1. Record thread state to provide a detailed breakdown, mimic race conditions.
  2. Lamda function support.
  3. Dynamic class support generated on the fly by ASM and other libraries.
  4. Support controlling execution flow, recording only the particular path through line numbers.
You might also like...

These samples explore the different options that Spring Boot developers have for using Javascript and CSS on the client (browser) side of their application.

These samples explore the different options that Spring Boot developers have for using Javascript and CSS on the client (browser) side of their application.

Table of Contents Getting Started Narrowing the Choices Create a New Application Webjars Show Me Some Javascript Normalizing Resource Paths Adding Tab

Jul 29, 2022

A simple and lightweight Minecraft GUI API for developers to use.

Current Version: 1.0.0 Requirements: - You must be using PaperMC or a fork of it (This will not work with just Spigot/Bukkit! - Curently this API only

May 14, 2022

This is a Maven plugin designed to help developers automatizing the creation of code classes from YML files based on AsyncApi and OpenAPI.

SCS MultiApi Maven Plugin This is a Maven plugin designed to help developers automatizing the creation of code classes from YML files based on AsyncAp

Dec 20, 2022

Community-Driven Game Server Development solution for Java Developers based on DEEPINTHINK MagOKO Project.

MagOKO Stack Community-Driven Game Server Development solution for Java Developers based on DEEPINTHINK MagOKO Project. License Copyright 2021-present

Jun 1, 2021

Rivr is a lightweight open-source dialogue engine enabling Java developers to easily create enterprise-grade VoiceXML applications.

Overview Rivr is a lightweight open-source dialogue engine enabling Java developers to easily create enterprise-grade VoiceXML applications. Read our

Jun 27, 2022

Java based open source static site/blog generator for developers & designers.

JBake JBake is a Java based open source static site/blog generator for developers. Documentation Full documentation is available on jbake.org. Contrib

Dec 30, 2022

My solutions for the MongoDB for Java Developers course

Welcome to M220J Disclaimer: The dependencies and versions in this project are not maintained. This project is intended for educational purposes and i

Jun 26, 2022

Features useful for Minecraft content developers.

Easy Development A mod to make Minecraft content development easier. Includes features primarily to assist with mod, resource pack, and datapack devel

Feb 15, 2022

Program that allows employees to clock in and clock out of work. Employees who are managers can add, edit and delete employees and shifts from the database.

Program that allows employees to clock in and clock out of work. Employees who are managers can add, edit and delete employees and shifts from the database.

Clock-In-Clock-Out-System Created by: Kennedy Janto, Taylor Vandenberg, Duc Nguyen, Alex Gomez, Janista Gitbumrungsin This is a semester long project

Nov 5, 2022
Owner
Kartik kalaghatgi
Pursuing B.E in computer_science @ SDM College of Engineering & Tech...
Kartik  kalaghatgi
A powerful API whichs allows developers to change a players name and UUID on login.

UUIDSwitcher An easy to use but powerful API for spigot servers which gives developers control over the UUID and name a player logs in with. This chan

BeefDev 6 Nov 30, 2022
A Maven extension for validating and collecting checksums of all artifacts during execution.

Maven checksum extension This extension allows for the creation and the enforcement of checksums for any artifact that is resolved by Maven. Without s

Rafael Winterhalter 12 Aug 6, 2022
Java controlled pub command execution

OPIUM - Operate pub interface under machine. This package allows operating pub command with Java object only and return console context. Perquisites C

Project Will Pub 1 Jan 23, 2022
Record builder generator for Java records

RecordBuilder What is RecordBuilder Java 16 introduces Records. While this version of records is fantastic, it's currently missing some important feat

Jordan Zimmerman 361 Dec 27, 2022
Log4j CVE-2021-44228 examples: Remote Code Execution (through LDAP, RMI, ...), Forced DNS queries, ...

Log4j CVE-2021-44228 and CVE-2021-45046 Requisites Use a vulnerable JDK, for instance JDK 1.8.0_181 Usage Malicious server The malicious server deploy

Manuel Álvarez Álvarez 5 Feb 7, 2022
A plugin that open the GC command execution interface for third-party clients

gc-opencommand-plugin 中文 | English 一个为第三方客户端开放GC命令执行接口的插件 服务端安装 在 Release 下载 jar 放入 plugins 文件夹即可 控制台连接 首次启动时,会在 plugins 目录下生成一个 opencommand-plugin 目录

筱傑 222 Jan 1, 2023
Representational State Transfer + Structured Query Language(RSQL): Demo application using RSQL parser to filter records based on provided condition(s)

Representational State Transfer + Structured Query Language: RSQL Demo application using RSQL parser to filter records based on provided condition(s)

Hardik Singh Behl 9 Nov 23, 2022
An examples of creating test records in the database with Spring Boot + Spring Data + JPA usage.

Spring Boot + JPA — Clear Tests An examples of creating test records in the database with Spring Boot + Spring Data + JPA usage. Check out the article

Semyon Kirekov 8 Nov 24, 2022
A compact and highly efficient workflow and Business Process Management (BPM) platform for developers, system admins and business users.

Flowable (V6) Maven Central: Docker Images: License: Homepage: https://www.flowable.org/ flowable / flowəb(ə)l / a compact and highly efficient workfl

Flowable 6k Jan 7, 2023
Alibaba Cloud Dedicated KMS Transfer SDK for Java can help Java developers to migrate from the KMS keys to the Dedicated KMS keys.

Alibaba Cloud Dedicated KMS Transfer SDK for Java Alibaba Cloud Dedicated KMS Transfer SDK for Java can help Java developers to migrate from the KMS k

Alibaba Cloud 3 May 12, 2022