Skip to content

Instantly share code, notes, and snippets.

@timo
Last active May 11, 2016 21:50
Show Gist options
  • Save timo/0dfba0c72f06509fd7ede85f5a021688 to your computer and use it in GitHub Desktop.
Save timo/0dfba0c72f06509fd7ede85f5a021688 to your computer and use it in GitHub Desktop.
Rakudo: perl6 -e 'say "hi"'; snapshot 1
> Name Total Bytes
======================================= =============
moarop_mapper (QAST.nqp:1821) 368,016 bytes
add_core_moarop_mapping (QAST.nqp:1794) 286,688 bytes
<anon> (m-CORE.setting:21673) 44,000 bytes
<unit> (m-CORE.setting:1) 38,824 bytes
<anon> (m-CORE.setting:2350) 30,976 bytes
new_type (m-Metamodel.nqp:1244) 20,672 bytes
new_type (m-Metamodel.nqp:2543) 17,464 bytes
add_hll_moarop_mapping (QAST.nqp:1806) 16,008 bytes
<anon> (m-CORE.setting:507) 15,120 bytes
<anon> (m-BOOTSTRAP.nqp:1708) 13,760 bytes
<mainline> (NQPCORE.setting:1) 12,360 bytes
<anon> (m-BOOTSTRAP.nqp:1069) 11,856 bytes
<anon> (m-BOOTSTRAP.nqp:2048) 10,880 bytes
<mainline> (m-BOOTSTRAP.nqp:1) 10,808 bytes
finish_code_object (World.nqp:2136) 10,296 bytes
Rakudo: perl6 -e 'say "hi"'; snapshot 1
> Name Total Bytes
=================================== =============
moarop_mapper (QAST.nqp:1836) 336,600 bytes
<anon> (m-CORE.setting:21673) 44,000 bytes
<unit> (m-CORE.setting:1) 38,824 bytes
<anon> (m-CORE.setting:2350) 30,976 bytes
new_type (m-Metamodel.nqp:1244) 20,672 bytes
new_type (m-Metamodel.nqp:2543) 17,464 bytes
<anon> (m-CORE.setting:507) 15,120 bytes
<anon> (m-BOOTSTRAP.nqp:1708) 13,760 bytes
<mainline> (NQPCORE.setting:1) 12,360 bytes
<anon> (m-BOOTSTRAP.nqp:1069) 11,856 bytes
<anon> (m-BOOTSTRAP.nqp:2048) 10,880 bytes
<mainline> (m-BOOTSTRAP.nqp:1) 10,808 bytes
finish_code_object (World.nqp:2136) 10,296 bytes
min (m-CORE.setting:4713) 9,936 bytes
<mainline> (QAST.nqp:1) 6,616 bytes
timo@schmetterling ~/p/e/moarvm-heapanalyzer (master|MERGING)>
nqp-m --profile=heap -e 'nqp::say("hi"); nqp::force_gc()'
hi
Recording heap snapshot
Recording completed
Writing heap snapshot to heap-snapshot-1463002507.74718
timo@schmetterling ~/p/e/moarvm-heapanalyzer (master|MERGING)> perl6 -Ilib bin/moar-ha heap-snapshot-1463002507.74718
Considering the snapshot...looks reasonable!
This file contains 1 heap snapshot. I've selected it for you.
Type `help` for available commands, or `exit` to exit.
> summary
Wait a moment, while I finish loading the snapshot...
top frames by size
Total heap size: 3,192,789 bytes
Total objects: 28,279
Total type objects: 214
Total STables (type tables): 215
Total frames: 155
Total references: 113,142
> Name Total Bytes
==================================== ===========
<mainline> (QAST.nqp:1) 6,600 bytes
add_getattr_op (QAST.nqp:4060) 3,472 bytes
<anon> (QASTNode.nqp:54) 2,240 bytes
<anon> (NQP.nqp:1499) 2,096 bytes
add_bindattr_op (QAST.nqp:4023) 1,984 bytes
boxer (QAST.nqp:3351) 1,888 bytes
<anon> (QAST.nqp:2533) 1,888 bytes
<anon> (QAST.nqp:2225) 1,856 bytes
<anon> (NQP.nqp:2129) 1,560 bytes
add_native_assign_op (QAST.nqp:4152) 1,440 bytes
<anon> (NQPP6QRegex.nqp:44) 1,432 bytes
<mainline> (NQPCORE.setting:1) 1,208 bytes
<anon> (QRegex.nqp:37) 1,208 bytes
<anon> (NQPP6QRegex.nqp:500) 1,128 bytes
<anon> (QAST.nqp:4415) 1,072 bytes
>
commit 99938e8ad5d01864f39421118ed97b9b15f7d551
Author: Timo Paulssen <timonator@perpetuum-immobile.de>
Date: Wed May 11 23:15:13 2016 +0200
use a different moarop mapper for core ops
diff --git a/src/vm/moar/QAST/QASTOperationsMAST.nqp b/src/vm/moar/QAST/QASTOperationsMAST.nqp
index 6f30348..b028eb0 100644
--- a/src/vm/moar/QAST/QASTOperationsMAST.nqp
+++ b/src/vm/moar/QAST/QASTOperationsMAST.nqp
@@ -300,9 +300,29 @@ class QAST::MASTOperations {
return %core_inlinability{$op} // 0;
}
+ my %core_mapper_moarops;
+ my %core_mapper_deconts;
+ my %core_mapper_returnargs;
+
+ my $premade_core_moarop_closure;
+
+ sub core_moarop_closure($self) {
+ -> $qastcomp, $op {
+ my $returnarg := -1;
+ if nqp::existskey(%core_mapper_returnargs, $op.op) {
+ $returnarg := %core_mapper_returnargs{$op.op};
+ }
+ $self.compile_mastop($qastcomp, %core_mapper_moarops{$op.op}, $op.list, %core_mapper_deconts{$op.op}, :$returnarg);
+ }
+ }
+
# Adds a core op that maps to a Moar op.
method add_core_moarop_mapping(str $op, str $moarop, $ret = -1, :$decont, :$inlinable = 1) {
- %core_ops{$op} := self.moarop_mapper($moarop, $ret, $decont);
+ self.register_moarop_mapper($moarop, $op, $ret, $decont);
+ if $premade_core_moarop_closure =:= NQPMu {
+ $premade_core_moarop_closure := core_moarop_closure(self);
+ }
+ %core_ops{$op} := $premade_core_moarop_closure;
self.set_core_op_inlinability($op, $inlinable);
self.set_core_op_result_type($op, moarop_return_type($moarop));
}
@@ -340,6 +360,28 @@ class QAST::MASTOperations {
$MVM_operand_write_reg;
}
+ method register_moarop_mapper(str $moarop, $op, $ret, $decont_in) {
+ if $ret != -1 {
+ self.check_ret_val($moarop, $ret);
+ }
+
+ my @deconts;
+ if nqp::islist($decont_in) {
+ for $decont_in { @deconts[$_] := 1; }
+ }
+ elsif nqp::defined($decont_in) {
+ @deconts[$decont_in] := 1;
+ }
+
+ %core_mapper_moarops{$op} := $moarop;
+ %core_mapper_deconts{$op} := @deconts;
+ if $ret != -1 {
+ %core_mapper_returnargs{$op} := $ret;
+ }
+
+ NQPMu;
+ }
+
# Returns a mapper closure for turning an operation into a Moar op.
# $ret is the 0-based index of which arg to use as the result when
# the moarop is void.
@@ -405,7 +447,7 @@ class QAST::MASTOperations {
%core_result_type{$op} := str;
}
}
-
+
# Sets op inlinability at a HLL level. (Can override at HLL level whether
# or not the HLL overrides the op itself.)
method set_hll_op_result_type(str $hll, str $op, $type) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment