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

[jvm] Put all @Override in place #639

Merged
merged 3 commits into from May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/vm/jvm/runtime/org/raku/nqp/io/AsyncFileHandle.java
Expand Up @@ -53,6 +53,7 @@ public AsyncFileHandle(ThreadContext tc, String filename, String mode) {
}
}

@Override
public void close(ThreadContext tc) {
try {
chan.close();
Expand All @@ -61,6 +62,7 @@ public void close(ThreadContext tc) {
}
}

@Override
public void setEncoding(ThreadContext tc, Charset cs) {
enc = cs.newEncoder();
dec = cs.newDecoder();
Expand All @@ -72,6 +74,7 @@ private class SlurpState {
}
private static final CallSiteDescriptor slurpResultCSD = new CallSiteDescriptor(
new byte[] { CallSiteDescriptor.ARG_OBJ }, null);
@Override
public void slurp(final ThreadContext tc, final SixModelObject Str,
final SixModelObject done, final SixModelObject error) {
try {
Expand Down Expand Up @@ -125,6 +128,7 @@ private class SpurtState {
new byte[] { }, null);
private static final CallSiteDescriptor spurtErrorCSD = new CallSiteDescriptor(
new byte[] { CallSiteDescriptor.ARG_OBJ }, null);
@Override
public void spurt(final ThreadContext tc, final SixModelObject Str, final SixModelObject data,
final SixModelObject done, final SixModelObject error) {
try {
Expand Down Expand Up @@ -177,6 +181,7 @@ private class LinesState {
public int total;
public int position;
}
@Override
public void lines(final ThreadContext tc, final SixModelObject Str,
final boolean chomp, final LinkedBlockingQueue<SixModelObject> queue,
final SixModelObject done, final SixModelObject error) {
Expand Down
120 changes: 58 additions & 62 deletions src/vm/jvm/runtime/org/raku/nqp/io/AsyncProcessHandle.java
Expand Up @@ -46,52 +46,50 @@ public AsyncProcessHandle(ThreadContext tc, SixModelObject queue, SixModelObject
this.tc = tc;
this.hllConfig = tc.curFrame.codeRef.staticInfo.compUnit.hllConfig;
this.bufType = config.get("buf_type");
Thread thread = new Thread(new Runnable() {
public void run() {
try {
AsyncProcessHandle.this.proc = pb.start();
procStarted = true;
Thread thread = new Thread(() -> {
try {
AsyncProcessHandle.this.proc = pb.start();
procStarted = true;

int pid = (int)getPID(AsyncProcessHandle.this.proc);
int pid = (int)getPID(AsyncProcessHandle.this.proc);

SixModelObject ready = config.get("ready");
if (Ops.isnull(ready) == 0) {
send(ready, null, boxInt(pid));
}
SixModelObject ready = config.get("ready");
if (Ops.isnull(ready) == 0) {
send(ready, null, boxInt(pid));
}

SixModelObject outputCallback = config.get("merge_bytes");
if (Ops.isnull(outputCallback) == 1)
outputCallback = config.get("stdout_bytes");
if (Ops.isnull(outputCallback) == 0)
launchReader(outputCallback, false);
SixModelObject outputCallback = config.get("merge_bytes");
if (Ops.isnull(outputCallback) == 1)
outputCallback = config.get("stdout_bytes");
if (Ops.isnull(outputCallback) == 0)
launchReader(outputCallback, false);

SixModelObject errorCallback = config.get("stderr_bytes");
if (Ops.isnull(errorCallback) == 0)
launchReader(errorCallback, true);
SixModelObject errorCallback = config.get("stderr_bytes");
if (Ops.isnull(errorCallback) == 0)
launchReader(errorCallback, true);

int outcome = AsyncProcessHandle.this.proc.waitFor();
SixModelObject done = config.get("done");
/* Return exit code left shifted by 8 for POSIX emulation. */
if (Ops.isnull(done) == 0)
send(done, boxInt(outcome << 8));
}
catch (Throwable t) {
SixModelObject message = boxError(t.toString());
int outcome = AsyncProcessHandle.this.proc.waitFor();
SixModelObject done = config.get("done");
/* Return exit code left shifted by 8 for POSIX emulation. */
if (Ops.isnull(done) == 0)
send(done, boxInt(outcome << 8));
}
catch (Throwable t) {
SixModelObject message = boxError(t.toString());

SixModelObject error = config.get("error");
if (Ops.isnull(error) == 0)
send(error, message);
SixModelObject error = config.get("error");
if (Ops.isnull(error) == 0)
send(error, message);

SixModelObject stdoutBytes = config.get("stdout_bytes");
if (Ops.isnull(stdoutBytes) == 0)
send(stdoutBytes, AsyncProcessHandle.this.hllConfig.intBoxType,
AsyncProcessHandle.this.hllConfig.strBoxType, message);
SixModelObject stdoutBytes = config.get("stdout_bytes");
if (Ops.isnull(stdoutBytes) == 0)
send(stdoutBytes, AsyncProcessHandle.this.hllConfig.intBoxType,
AsyncProcessHandle.this.hllConfig.strBoxType, message);

SixModelObject stderrBytes = config.get("stderr_bytes");
if (Ops.isnull(stderrBytes) == 0)
send(stderrBytes, AsyncProcessHandle.this.hllConfig.intBoxType,
AsyncProcessHandle.this.hllConfig.strBoxType, message);
}
SixModelObject stderrBytes = config.get("stderr_bytes");
if (Ops.isnull(stderrBytes) == 0)
send(stderrBytes, AsyncProcessHandle.this.hllConfig.intBoxType,
AsyncProcessHandle.this.hllConfig.strBoxType, message);
}
});
thread.setDaemon(true);
Expand Down Expand Up @@ -122,7 +120,7 @@ private Map<String, String> getEnv(ThreadContext tc, SixModelObject envObj) {
}

private Map<String, SixModelObject> getConfig(ThreadContext tc, SixModelObject configObj) {
Map<String, SixModelObject> env = new HashMap<String, SixModelObject>();
Map<String, SixModelObject> env = new HashMap<>();
SixModelObject iter = Ops.iter(configObj, tc);
while (Ops.istrue(iter, tc) != 0) {
SixModelObject kv = iter.shift_boxed(tc);
Expand Down Expand Up @@ -172,32 +170,30 @@ private void launchReader(final SixModelObject callback, final boolean stderr) {
final InputStream stream = stderr
? this.proc.getErrorStream()
: this.proc.getInputStream();
new Thread(new Runnable() {
public void run() {
try {
byte[] buffer;
int read;
while ((read = stream.read(buffer = new byte[32768])) != -1) {
SixModelObject result = Ops.create(AsyncProcessHandle.this.bufType, tc);
Buffers.stashBytes(tc, result, buffer, read);
send(callback,
boxInt(stderr
? AsyncProcessHandle.this.errSeq++
: AsyncProcessHandle.this.outSeq++),
result,
AsyncProcessHandle.this.hllConfig.strBoxType);
}
new Thread(() -> {
try {
byte[] buffer;
int read;
while ((read = stream.read(buffer = new byte[32768])) != -1) {
SixModelObject result = Ops.create(AsyncProcessHandle.this.bufType, tc);
Buffers.stashBytes(tc, result, buffer, read);
send(callback,
boxInt(stderr
? AsyncProcessHandle.this.errSeq++
: AsyncProcessHandle.this.outSeq++),
AsyncProcessHandle.this.hllConfig.strBoxType,
result,
AsyncProcessHandle.this.hllConfig.strBoxType);
}
catch (Throwable t) {
send(callback, boxInt(-1), AsyncProcessHandle.this.hllConfig.strBoxType,
boxError(t.toString()));
}
send(callback,
boxInt(stderr
? AsyncProcessHandle.this.errSeq++
: AsyncProcessHandle.this.outSeq++),
AsyncProcessHandle.this.hllConfig.strBoxType,
AsyncProcessHandle.this.hllConfig.strBoxType);
}
catch (Throwable t) {
send(callback, boxInt(-1), AsyncProcessHandle.this.hllConfig.strBoxType,
boxError(t.toString()));
}
}).start();
}
Expand Down Expand Up @@ -243,9 +239,9 @@ public synchronized void writeBytes(ThreadContext tc, AsyncTaskInstance task, Si
((ConcBlockingQueueInstance)task.queue).push_boxed(tc, result);
}

static interface Kernel32 extends Library {
public static Kernel32 INSTANCE = (Kernel32)Native.loadLibrary("kernel32", Kernel32.class);
public int GetProcessId(Long hProcess);
interface Kernel32 extends Library {
Kernel32 INSTANCE = (Kernel32)Native.loadLibrary("kernel32", Kernel32.class);
int GetProcessId(Long hProcess);
}

private long getPID(Process proc) {
Expand Down
20 changes: 13 additions & 7 deletions src/vm/jvm/runtime/org/raku/nqp/io/FileHandle.java
Expand Up @@ -26,7 +26,7 @@ public OpenOption[] resolveOpenMode(String mode) {
return null;

int pos = 0;
List<OpenOption> opts = new ArrayList<OpenOption>();
List<OpenOption> opts = new ArrayList<>();

switch (mode.charAt(pos++)) {
case 'r': opts.add(StandardOpenOption.READ); break;
Expand All @@ -53,7 +53,7 @@ public OpenOption[] resolveOpenMode(String mode) {
}

/* work around differences between Perl 6 and FileChannel.open */
List<OpenOption> optsToRemove = new ArrayList<OpenOption>();
List<OpenOption> optsToRemove = new ArrayList<>();
if (opts.contains(StandardOpenOption.READ)) {
/* APPEND may not be used in conjunction with READ. */
if (opts.contains(StandardOpenOption.APPEND)) {
Expand Down Expand Up @@ -81,15 +81,14 @@ public FileHandle(ThreadContext tc, String filename, String mode) {
} catch (IOException e) {
throw ExceptionHandling.dieInternal(tc, e);
}
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
if (chan.isOpen()) {
close(tc);
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (chan.isOpen()) {
close(tc);
}
}));
}

@Override
public long write(ThreadContext tc, byte[] array) {
if (append) {
try {
Expand All @@ -104,6 +103,7 @@ public long write(ThreadContext tc, byte[] array) {
return super.write(tc, array);
}

@Override
public long print(ThreadContext tc, String s) {
if (append) {
try {
Expand All @@ -118,6 +118,7 @@ public long print(ThreadContext tc, String s) {
return super.print(tc, s);
}

@Override
public void seek(ThreadContext tc, long offset, long whence) {
try {
flushWriteBuffer(tc);
Expand Down Expand Up @@ -145,6 +146,7 @@ public void seek(ThreadContext tc, long offset, long whence) {
eof = false;
}

@Override
public long tell(ThreadContext tc) {
try {
flushWriteBuffer(tc);
Expand All @@ -155,6 +157,7 @@ public long tell(ThreadContext tc) {
}
}

@Override
public void lock(ThreadContext tc, long flag) {
if (lock != null && lock.acquiredBy() == fc) {
/* XXX: *might* not be quite the exact condition we want,
Expand All @@ -176,6 +179,7 @@ public void lock(ThreadContext tc, long flag) {
}
}

@Override
public void unlock(ThreadContext tc) {
try {
if (lock != null) {
Expand All @@ -189,6 +193,7 @@ public void unlock(ThreadContext tc) {
}
}

@Override
public void flush(ThreadContext tc) {
try {
flushWriteBuffer(tc);
Expand All @@ -198,6 +203,7 @@ public void flush(ThreadContext tc) {
}
}

@Override
public boolean eof(ThreadContext tc) {
if (eof)
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/vm/jvm/runtime/org/raku/nqp/io/IIOAsyncReadable.java
Expand Up @@ -6,9 +6,9 @@
import org.raku.nqp.sixmodel.SixModelObject;

public interface IIOAsyncReadable {
public void slurp(ThreadContext tc, SixModelObject Str, SixModelObject done,
void slurp(ThreadContext tc, SixModelObject Str, SixModelObject done,
SixModelObject error);
public void lines(ThreadContext tc, SixModelObject Str, boolean chomp,
void lines(ThreadContext tc, SixModelObject Str, boolean chomp,
LinkedBlockingQueue<SixModelObject> queue, SixModelObject done,
SixModelObject error);
}
2 changes: 1 addition & 1 deletion src/vm/jvm/runtime/org/raku/nqp/io/IIOAsyncWritable.java
Expand Up @@ -4,6 +4,6 @@
import org.raku.nqp.sixmodel.SixModelObject;

public interface IIOAsyncWritable {
public void spurt(ThreadContext tc, SixModelObject Str, SixModelObject data, SixModelObject done,
void spurt(ThreadContext tc, SixModelObject Str, SixModelObject data, SixModelObject done,
SixModelObject error);
}
2 changes: 1 addition & 1 deletion src/vm/jvm/runtime/org/raku/nqp/io/IIOBindable.java
Expand Up @@ -4,6 +4,6 @@

public interface IIOBindable {

public void bind(ThreadContext tc, String host, int port, int backlog);
void bind(ThreadContext tc, String host, int port, int backlog);

}
2 changes: 1 addition & 1 deletion src/vm/jvm/runtime/org/raku/nqp/io/IIOCancelable.java
Expand Up @@ -4,5 +4,5 @@

public interface IIOCancelable {

public void cancel(ThreadContext tc);
void cancel(ThreadContext tc);
}
2 changes: 1 addition & 1 deletion src/vm/jvm/runtime/org/raku/nqp/io/IIOClosable.java
Expand Up @@ -3,5 +3,5 @@
import org.raku.nqp.runtime.ThreadContext;

public interface IIOClosable {
public void close(ThreadContext tc);
void close(ThreadContext tc);
}
2 changes: 1 addition & 1 deletion src/vm/jvm/runtime/org/raku/nqp/io/IIOEncodable.java
Expand Up @@ -5,5 +5,5 @@
import org.raku.nqp.runtime.ThreadContext;

public interface IIOEncodable {
public void setEncoding(ThreadContext tc, Charset cs);
void setEncoding(ThreadContext tc, Charset cs);
}
2 changes: 1 addition & 1 deletion src/vm/jvm/runtime/org/raku/nqp/io/IIOExitable.java
Expand Up @@ -3,5 +3,5 @@
import org.raku.nqp.runtime.ThreadContext;

public interface IIOExitable {
public int exitValue(ThreadContext tc) throws IllegalThreadStateException;
int exitValue(ThreadContext tc) throws IllegalThreadStateException;
}
2 changes: 1 addition & 1 deletion src/vm/jvm/runtime/org/raku/nqp/io/IIOInteractive.java
Expand Up @@ -3,5 +3,5 @@
import org.raku.nqp.runtime.ThreadContext;

public interface IIOInteractive {
public String readlineInteractive(ThreadContext tc, String prompt);
String readlineInteractive(ThreadContext tc, String prompt);
}
2 changes: 1 addition & 1 deletion src/vm/jvm/runtime/org/raku/nqp/io/IIOLineSeparable.java
Expand Up @@ -3,5 +3,5 @@
import org.raku.nqp.runtime.ThreadContext;

public interface IIOLineSeparable {
public void setInputLineSeparator(ThreadContext tc, String sep);
void setInputLineSeparator(ThreadContext tc, String sep);
}
4 changes: 2 additions & 2 deletions src/vm/jvm/runtime/org/raku/nqp/io/IIOLockable.java
Expand Up @@ -3,6 +3,6 @@
import org.raku.nqp.runtime.ThreadContext;

public interface IIOLockable {
public void lock(ThreadContext tc, long flag);
public void unlock(ThreadContext tc);
void lock(ThreadContext tc, long flag);
void unlock(ThreadContext tc);
}
2 changes: 1 addition & 1 deletion src/vm/jvm/runtime/org/raku/nqp/io/IIOPossiblyTTY.java
Expand Up @@ -3,5 +3,5 @@
import org.raku.nqp.runtime.ThreadContext;

public interface IIOPossiblyTTY {
public boolean isTTY(ThreadContext tc);
boolean isTTY(ThreadContext tc);
}
4 changes: 2 additions & 2 deletions src/vm/jvm/runtime/org/raku/nqp/io/IIOSeekable.java
Expand Up @@ -3,6 +3,6 @@
import org.raku.nqp.runtime.ThreadContext;

public interface IIOSeekable {
public void seek(ThreadContext tc, long offset, long whence);
public long tell(ThreadContext tc);
void seek(ThreadContext tc, long offset, long whence);
long tell(ThreadContext tc);
}