Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Development #4

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/main/java/de/hhu/bsinfo/dxmem/operations/NoParamCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.hhu.bsinfo.dxmem.operations;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;

/**
* Indicates that the parameters of the targets are not checked for having a better performance.
* It means that u have to take look into javadoc for this target how u use should use it. Remember it while debugging.
* <p>
* In context of DXMem especially the Raw operations you can damage the memory structure. So use the target carefully
*
* @author Lars Mehnert
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(value = {TYPE, METHOD, CONSTRUCTOR})
public @interface NoParamCheck {
}
21 changes: 21 additions & 0 deletions src/main/java/de/hhu/bsinfo/dxmem/operations/PinnedMemory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.hhu.bsinfo.dxmem.operations;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;

/**
* Indicates that the class or the package presuppose, that they have to use in an context, where the memory is pinned.
* So you can use the target while you have pinned the memory but for other uses it is not safe that it will work.
*
* @author Lars Mehnert
* @see de.hhu.bsinfo.dxmem.operations.Pinning.PinnedMemory
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(value = {TYPE})
public @interface PinnedMemory {
}
59 changes: 59 additions & 0 deletions src/main/java/de/hhu/bsinfo/dxmem/operations/RawCompare.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package de.hhu.bsinfo.dxmem.operations;

import de.hhu.bsinfo.dxmem.core.Context;

/**
* A class for compare Operations based on physical addresses.
*
* @author Lars Mehnert
*/
@PinnedMemory
public class RawCompare {

private final Context m_context;

/**
* Constructor
*
* @param p_context Context
*/
public RawCompare(final Context p_context) {
m_context = p_context;
}

/**
* Compare a byte at a given address + offset with a given byte.
*
* @param p_address physical address
* @param p_offset offset that will be added on p_address
* @param p_suspect byte which will be compared
* @return true if the given byte are equal to the read byte
*/
public boolean compare(final long p_address, final int p_offset, final byte p_suspect) {
return m_context.getHeap().readByte(p_address, p_offset) == p_suspect;
}

/**
* Compares a byte array at a given address + offset with a given byte array.
* It iterates over the byte array and will return if it found a unequal at current iteration.
* <p>
* Special attention to the range it will ce compare. The length of the given byte array is equal to the
LarsMeh marked this conversation as resolved.
Show resolved Hide resolved
* number of iterations.
* For the byte comparison it uses the {@link #compare(long, int, byte)} method.
*
* @param p_address physical address
* @param p_offset offset that will be added on p_address
* @param p_suspect byte array which will be compared
* @return true if the byte array is completely equal.
*/
public boolean compare(final long p_address, final int p_offset, final byte[] p_suspect) {
int offset = p_offset;
for (int i = 0; i < p_suspect.length; i++) {
if (compare(p_address, offset, p_suspect[i]))
LarsMeh marked this conversation as resolved.
Show resolved Hide resolved
return false;
offset += Byte.BYTES;
}
return true;
}

}