Skip to content

Commit

Permalink
Merge pull request #553 from Kaiepi/mem
Browse files Browse the repository at this point in the history
Implement freemem and totalmem ops
  • Loading branch information
ugexe committed Jun 10, 2019
2 parents 86f2366 + 4e9178a commit 26754f1
Show file tree
Hide file tree
Showing 26 changed files with 28 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/vm/js/Operations.nqp
Expand Up @@ -1910,6 +1910,8 @@ class QAST::OperationsJS {
add_simple_op('uname', $T_OBJ, [], :side_effects);

add_simple_op('cpucores', $T_INT, []);
add_simple_op('freemem', $T_INT, []);
add_simple_op('totalmem', $T_INT, []);

add_simple_op('unicmp_s', $T_INT, [$T_STR, $T_STR, $T_INT, $T_INT, $T_INT]);

Expand Down
8 changes: 8 additions & 0 deletions src/vm/js/nqp-runtime/core.js
Expand Up @@ -2091,6 +2091,14 @@ op.cpucores = function() {
return os.cpus().length;
};

op.freemem = function() {
return os.freemem();
};

op.totalmem = function() {
return os.totalmem();
};

op.atomicinc_i = function(ctx, ref) {
const value = ref.$$getInt();
ref.$$assign_i(ctx, value+1);
Expand Down
2 changes: 2 additions & 0 deletions src/vm/jvm/QAST/Compiler.nqp
Expand Up @@ -2870,6 +2870,8 @@ QAST::OperationsJAST.map_classlib_core_op('semtryacquire', $TYPE_OPS, 'semtryacq
QAST::OperationsJAST.map_classlib_core_op('semrelease', $TYPE_OPS, 'semrelease', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('queuepoll', $TYPE_OPS, 'queuepoll', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('cpucores', $TYPE_OPS, 'cpucores', [], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('freemem', $TYPE_OPS, 'freemem', [], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('totalmem', $TYPE_OPS, 'totalmem', [], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('threadlockcount', $TYPE_OPS, 'threadlockcount', [$RT_OBJ], $RT_INT, :tc);

# asynchrony related ops
Expand Down
19 changes: 14 additions & 5 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -13,6 +13,7 @@
import java.lang.reflect.Method;
import java.lang.ProcessHandle;
import java.lang.ProcessBuilder.Redirect;
import java.lang.Runtime;
import java.lang.Thread;
import java.math.BigDecimal;
import java.math.BigInteger;
Expand Down Expand Up @@ -4289,17 +4290,17 @@ public static long eqatic(String haystack, String needle, long offset) {
public static long ordfirst(String str) {
if (str.isEmpty()) {
return -1;
}
else {
}
else {
return str.codePointAt(0);
}
}
}

public static long ordat(String str, long offset) {
if (offset < 0 || offset >= str.length()) {
return -1;
}
else {
else {
return str.codePointAt((int)offset);
}
}
Expand All @@ -4308,7 +4309,7 @@ public static long ordbaseat(String str, long offset) {
if (offset < 0 || offset >= str.length()) {
return -1;
}
else {
else {
int code = str.codePointAt((int)offset);
String letter = new String(new int[]{code}, 0, 1);
return Normalizer.normalize(letter, Normalizer.Form.NFD).codePointAt(0);
Expand Down Expand Up @@ -5805,6 +5806,14 @@ public static long cpucores(ThreadContext tc) {
return Runtime.getRuntime().availableProcessors();
}

public static long freemem(ThreadContext tc) {
return Runtime.getRuntime().freeMemory();
}

public static long totalmem(ThreadContext tc) {
return Runtime.getRuntime().totalMemory();
}

public static SixModelObject lock(SixModelObject lock, ThreadContext tc) {
if (lock instanceof ReentrantMutexInstance) {
((ReentrantMutexInstance)lock).lock.lock();
Expand Down
Binary file modified src/vm/jvm/stage0/JASTNodes.jar
Binary file not shown.
Binary file modified src/vm/jvm/stage0/ModuleLoader.jar
Binary file not shown.
Binary file modified src/vm/jvm/stage0/NQPCORE.setting.jar
Binary file not shown.
Binary file modified src/vm/jvm/stage0/NQPHLL.jar
Binary file not shown.
Binary file modified src/vm/jvm/stage0/NQPP6QRegex.jar
Binary file not shown.
Binary file modified src/vm/jvm/stage0/QAST.jar
Binary file not shown.
Binary file modified src/vm/jvm/stage0/QASTNode.jar
Binary file not shown.
Binary file modified src/vm/jvm/stage0/QRegex.jar
Binary file not shown.
Binary file modified src/vm/jvm/stage0/nqp.jar
Binary file not shown.
Binary file modified src/vm/jvm/stage0/nqpmo.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions src/vm/moar/QAST/QASTOperationsMAST.nqp
Expand Up @@ -3136,6 +3136,8 @@ QAST::MASTOperations.add_core_moarop_mapping('semtryacquire', 'semtryacquire');
QAST::MASTOperations.add_core_moarop_mapping('semrelease', 'semrelease');
QAST::MASTOperations.add_core_moarop_mapping('queuepoll', 'queuepoll');
QAST::MASTOperations.add_core_moarop_mapping('cpucores', 'cpucores');
QAST::MASTOperations.add_core_moarop_mapping('freemem', 'freemem');
QAST::MASTOperations.add_core_moarop_mapping('totalmem', 'totalmem');
QAST::MASTOperations.add_core_moarop_mapping('threadlockcount', 'threadlockcount');

# asynchrony related ops
Expand Down
Binary file modified src/vm/moar/stage0/MASTNodes.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/MASTOps.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/ModuleLoader.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/NQPCORE.setting.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/NQPHLL.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/NQPP6QRegex.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/QAST.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/QASTNode.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/QRegex.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/nqp.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/nqpmo.moarvm
Binary file not shown.

0 comments on commit 26754f1

Please sign in to comment.