Skip to content

Commit

Permalink
Merge 5f6e338 into 50cd03e
Browse files Browse the repository at this point in the history
  • Loading branch information
smarr committed Jul 19, 2018
2 parents 50cd03e + 5f6e338 commit 8a7904c
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -43,7 +43,7 @@ matrix:
language: generic
env: TASK=unit-tests
before_install: |
brew tap caskroom/versions
brew update
brew cask reinstall java
brew install ant
export JAVA_HOME=`/usr/libexec/java_home`
Expand Down
55 changes: 55 additions & 0 deletions core-lib/Benchmarks/LanguageFeatures.ns
Expand Up @@ -25,6 +25,7 @@ class LanguageFeaturesSuite usingPlatform: platform andHarness: harness = (
private Vector = platform kernel Vector.
private Exception = platform kernel Exception.
private ObjectMirror = platform mirrors ObjectMirror.
private FilePath = platform files FilePath.
private one = 5555.
|
)(
Expand Down Expand Up @@ -660,4 +661,58 @@ class LanguageFeaturesSuite usingPlatform: platform andHarness: harness = (
public newInstance = ( ^ self new )
public setupVerifiedRun: run = ( run innerIterations: 1 )
)

public class StringCharAt = Benchmark (
| private str = '012345678901234567890123456789012345678901234567890123456789'. |
)(
public benchmark = (
| i ::= 1. |
1 to: 6 do: [:k |
0 to: 9 do: [:j |
| chr |
chr:: str charAt: i.
j asString = chr ifFalse: [ ^ false ].
i:: i + 1. ] ].
^ true
)

public verifyResult: result = (
^ true
)
) : (
public newInstance = ( ^ self new )
public setupVerifiedRun: run = ( run innerIterations: 1 )
)

public class FileReadWrite = Benchmark (
| private modulePath = (ObjectMirror reflecting: self) classMirror classDefinition filePath.
private path = ((FilePath for: modulePath)
containingDirectory
containingDirectory
containingDirectory / 'tests' / 'files') pattern.
private f = FilePath for: path + '/benchmark-tmp'.
private d = f open: #readWrite.
|
0 to: 255 do:[ :i|
d buffer at: i + 1 put: i - 128.
].
)(
public innerBenchmarkLoop: innerIterations numThreads: threads = (
| result |
result:: super innerBenchmarkLoop: innerIterations numThreads: threads.
^ result
)

public benchmark = (
d write: 256 at: 0.
^ d readAt: 0
)

public verifyResult: result = (
^ result = 256
)
) : (
public newInstance = ( ^ self new )
public setupVerifiedRun: run = ( run innerIterations: 1 )
)
)
9 changes: 7 additions & 2 deletions src/som/primitives/FilePrims.java
Expand Up @@ -6,6 +6,7 @@
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.source.SourceSection;

import bd.primitives.Primitive;
Expand Down Expand Up @@ -181,18 +182,22 @@ public final Object fileOpen(final SFileDescriptor file, final SBlock handler) {
@GenerateNodeFactory
@Primitive(primitive = "file:readAt:ifFail:")
public abstract static class ReadFilePrim extends TernaryExpressionNode {
private final BranchProfile errorCases = BranchProfile.create();

@Child protected BlockDispatchNode dispatchHandler = BlockDispatchNodeGen.create();

@Specialization
public final long read(final SFileDescriptor file, final long offset,
final SBlock fail) {
return file.read(offset, fail, dispatchHandler);
return file.read(offset, fail, dispatchHandler, errorCases);
}
}

@GenerateNodeFactory
@Primitive(primitive = "file:write:at:ifFail:")
public abstract static class WriteFilePrim extends QuaternaryExpressionNode {
private final BranchProfile errorCases = BranchProfile.create();

@Child protected BlockDispatchNode dispatchHandler = BlockDispatchNodeGen.create();
@Child protected ExceptionSignalingNode ioException;

Expand All @@ -208,7 +213,7 @@ public ExpressionNode initialize(final SourceSection sourceSection,
@Specialization
public final Object write(final SFileDescriptor file, final long nBytes,
final long offset, final SBlock fail) {
file.write((int) nBytes, offset, fail, dispatchHandler, ioException);
file.write((int) nBytes, offset, fail, dispatchHandler, ioException, errorCases);
return file;
}
}
Expand Down
21 changes: 17 additions & 4 deletions src/som/vmobjects/SFileDescriptor.java
Expand Up @@ -6,6 +6,8 @@
import java.io.RandomAccessFile;

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.ValueProfile;

import som.interpreter.nodes.ExceptionSignalingNode;
import som.interpreter.nodes.dispatch.BlockDispatchNode;
Expand All @@ -16,6 +18,9 @@


public class SFileDescriptor extends SObjectWithClass {
/** Data buffers in this file descriptor are expected to contain only integers. */
private static final ValueProfile longStorageType = ValueProfile.createClassProfile();

@CompilationFinal public static SClass fileDescriptorClass;

private static final SSymbol FILE_NOT_FOUND = Symbols.symbolFor("FileNotFound");
Expand Down Expand Up @@ -68,18 +73,20 @@ public void closeFile(final ExceptionSignalingNode ioException) {
}

public int read(final long position, final SBlock fail,
final BlockDispatchNode dispatchHandler) {
final BlockDispatchNode dispatchHandler, final BranchProfile errorCases) {
if (raf == null) {
errorCases.enter();
fail.getMethod().invoke(new Object[] {fail, FILE_IS_CLOSED});
return 0;
}

if (accessMode == AccessModes.write) {
errorCases.enter();
fail.getMethod().invoke(new Object[] {fail, WRITE_ONLY_MODE});
return 0;
}

long[] storage = (long[]) buffer.getStoragePlain();
long[] storage = buffer.getLongStorage(longStorageType);
byte[] buff = new byte[bufferSize];
int bytes = 0;

Expand All @@ -90,6 +97,7 @@ public int read(final long position, final SBlock fail,
raf.seek(position);
bytes = raf.read(buff);
} catch (IOException e) {
errorCases.enter();
dispatchHandler.executeDispatch(new Object[] {fail, e.toString()});
}

Expand All @@ -102,22 +110,26 @@ public int read(final long position, final SBlock fail,
}

public void write(final int nBytes, final long position, final SBlock fail,
final BlockDispatchNode dispatchHandler, final ExceptionSignalingNode ioException) {
final BlockDispatchNode dispatchHandler, final ExceptionSignalingNode ioException,
final BranchProfile errorCases) {
if (raf == null) {
errorCases.enter();
dispatchHandler.executeDispatch(new Object[] {fail, FILE_IS_CLOSED});
return;
}

if (accessMode == AccessModes.read) {
errorCases.enter();
fail.getMethod().invoke(new Object[] {fail, READ_ONLY_MODE});
return;
}

long[] storage = (long[]) buffer.getStoragePlain();
long[] storage = buffer.getLongStorage(longStorageType);
byte[] buff = new byte[bufferSize];

for (int i = 0; i < bufferSize; i++) {
if (storage[i] <= Byte.MIN_VALUE && Byte.MAX_VALUE <= storage[i]) {
errorCases.enter();
ioException.signal(
"Buffer only supports values in the range -128 to 127 (" + storage[i] + ")");
}
Expand All @@ -128,6 +140,7 @@ public void write(final int nBytes, final long position, final SBlock fail,
raf.seek(position);
raf.write(buff, 0, nBytes);
} catch (IOException e) {
errorCases.enter();
dispatchHandler.executeDispatch(new Object[] {fail, e.toString()});
}
}
Expand Down
Binary file modified tests/dym/expected-results.tar.bz2
Binary file not shown.
Binary file modified tests/superinstructions/expected-results.tar.bz2
Binary file not shown.

0 comments on commit 8a7904c

Please sign in to comment.