On 06/11/2013 20:56, Gwenaël Casaccio wrote:
On 06/11/2013 13:05, Paolo Bonzini wrote:
Il 06/11/2013 10:25, Gwenaël Casaccio ha scritto:
The other implementation uses the bit check, nothing really special
here :) I've made
a simple "benchmark" and the difference between both approaches is not
really noticeable.
Frankly speaking I don't know what is the best approach to use (using
write barrier or not).
I think it could be nice to use an other heap for the read only
objects:
there are less wrong
positive with grey pages.
I think most read-only objects are old (and mmap-ed directly from the
image) anyway, so it shouldn't be a big change.
You've right
I see at least two issues the first with C programs and the write
barrier that uses
libgst and write an object directly the handler is not correct in that
case.
Yes, C programs might expect to be able to write to read-only objects.
Second issue - in both cases - with the bytecode set for instance if
it's the bc 80
and I send an tryToWriteAt::put: message and if the code simply returns
it's
going to crash.
I think whatever #tryToWriteAt:put: returns should be left on the stack.
So this:
Object subclass: A [
| a |
tryToWriteAt: index put: object [ ^42 ]
test [ (a := 123) printNl. a printNl ]
]
Eval [
A new
makeReadOnly: true;
test
]
should print
42 "result of #tryToWriteAt:put:"
nil "nothing was stored actually"
Paolo
Yes I agree for the stack, I'm thinking about the bytecode combination
if in the bc 80
I send a message when it leave the message the ip is the next ip and
it will go to the next
instruction and for the bc 80 it's bad because it's the last
instruction, if I'm right.
Gwen
Here is a first attempt to add RO supports what do you think ?
Gwen
>From 2702b059c618839efb187b9d4f1c8ff02f7976d7 Mon Sep 17 00:00:00 2001
From: Gwenael Casaccio <[email protected]>
Date: Thu, 7 Nov 2013 10:24:44 +0100
Subject: [PATCH] Read-only objects
---
libgst/byte.def | 10 +++-------
libgst/superop2.inl | 6 +++---
libgst/sym.c | 2 ++
libgst/sym.h | 1 +
libgst/vm.def | 26 ++++++++++++++++++--------
5 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/libgst/byte.def b/libgst/byte.def
index 88b7dbd..95ffb97 100644
--- a/libgst/byte.def
+++ b/libgst/byte.def
@@ -614,9 +614,7 @@ INVALID (opcode, arg);
RETURN_CONTEXT_STACK_TOP(0) */
80 {
extract opcode (8), arg_lsb (8);
- dispatch STORE_RECEIVER_VARIABLE (arg | arg_lsb);
- dispatch PUSH_SELF;
- dispatch RETURN_CONTEXT_STACK_TOP;
+ dispatch INVALID (80, arg | arg_lsb);
}
/* PUSH_INTEGER(*)
@@ -948,8 +946,7 @@ INVALID (opcode, arg);
POP_STACK_TOP(0) */
120 {
extract opcode (8), arg_lsb (8);
- dispatch STORE_RECEIVER_VARIABLE (arg | arg_lsb);
- dispatch POP_STACK_TOP;
+ dispatch INVALID (120, arg | arg_lsb);
}
/* EXT_BYTE(*)
@@ -2093,8 +2090,7 @@ INVALID (opcode, arg);
RETURN_CONTEXT_STACK_TOP(0) */
248 {
extract opcode (8), arg_lsb (8);
- dispatch STORE_RECEIVER_VARIABLE (arg | arg_lsb);
- dispatch RETURN_CONTEXT_STACK_TOP;
+ dispatch INVALID (248, arg | arg_lsb);
}
/* LINE_NUMBER_BYTECODE(*)
diff --git a/libgst/superop2.inl b/libgst/superop2.inl
index 7b09c25..37d05e5 100644
--- a/libgst/superop2.inl
+++ b/libgst/superop2.inl
@@ -36,7 +36,7 @@
};
static const struct superop_with_fixed_arg_2_type keylist[] =
{
- {{ 39, 48, 0}, 120},
+ {{}, -1}, // {{ 39, 48, 0}, 120},
{{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 },
{{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 },
{{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 },
@@ -55,7 +55,7 @@
{{ 46, 30, 49}, 117},
{{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 },
{{}, -1 }, {{}, -1 }, {{}, -1 },
- {{ 39, 51, 0}, 248},
+ {{}, -1}, // {{ 39, 51, 0}, 248},
{{ 68, 91, 0}, 234},
{{ 121, 51, 0}, 214},
{{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 }, {{}, -1 },
@@ -73,7 +73,7 @@
{{ 69, 51, 0}, 252},
{{ 54, 75, 0}, 185},
{{ 54, 48, 0}, 68},
- {{ 39, 66, 0}, 80},
+ {{}, -1}, // {{ 39, 66, 0}, 80},
{{}, -1 },
{{ 44, 14, 0}, 159},
{{}, -1 }, {{}, -1 }, {{}, -1 },
diff --git a/libgst/sym.c b/libgst/sym.c
index bbc3e9d..ea333ee 100644
--- a/libgst/sym.c
+++ b/libgst/sym.c
@@ -130,6 +130,7 @@ OOP _gst_int_symbol = NULL;
OOP _gst_long_double_symbol = NULL;
OOP _gst_long_symbol = NULL;
OOP _gst_must_be_boolean_symbol = NULL;
+OOP _gst_write_barrier_symbol = NULL;
OOP _gst_nil_symbol = NULL;
OOP _gst_or_symbol = NULL;
OOP _gst_permission_symbol = NULL;
@@ -284,6 +285,7 @@ static const symbol_info sym_info[] = {
{&_gst_long_symbol, "long"},
{&_gst_ulong_symbol, "uLong"},
{&_gst_must_be_boolean_symbol, "mustBeBoolean"},
+ {&_gst_write_barrier_symbol, "writeAt:put:"},
{&_gst_nil_symbol, "nil"},
{&_gst_or_symbol, "or:"},
{&_gst_primitive_symbol, "primitive:"},
diff --git a/libgst/sym.h b/libgst/sym.h
index 87c1f1c..30a5a69 100644
--- a/libgst/sym.h
+++ b/libgst/sym.h
@@ -119,6 +119,7 @@ extern OOP _gst_int_symbol ATTRIBUTE_HIDDEN;
extern OOP _gst_long_double_symbol ATTRIBUTE_HIDDEN;
extern OOP _gst_long_symbol ATTRIBUTE_HIDDEN;
extern OOP _gst_must_be_boolean_symbol ATTRIBUTE_HIDDEN;
+extern OOP _gst_write_barrier_symbol ATTRIBUTE_HIDDEN;
extern OOP _gst_nil_symbol ATTRIBUTE_HIDDEN;
extern OOP _gst_or_symbol ATTRIBUTE_HIDDEN;
extern OOP _gst_permission_symbol ATTRIBUTE_HIDDEN;
diff --git a/libgst/vm.def b/libgst/vm.def
index 7d48bdf..c0f23db 100644
--- a/libgst/vm.def
+++ b/libgst/vm.def
@@ -755,7 +755,21 @@ operation STORE_LIT_VARIABLE n ( tos -- tos ) {
}
operation STORE_RECEIVER_VARIABLE n ( tos -- tos ) {
- STORE_RECEIVER_VARIABLE (n, tos);
+ if COMMON (!IS_OOP_READONLY (_gst_self))
+ {
+ STORE_RECEIVER_VARIABLE (n, tos);
+ }
+ else
+ {
+ PREPARE_STACK ();
+ PUSH_OOP (_gst_self);
+ PUSH_OOP (FROM_INT (n));
+ PUSH_OOP (tos);
+ EXPORT_REGS();
+ SEND_MESSAGE(_gst_write_barrier_symbol, 2);
+ IMPORT_REGS();
+ FETCH;
+ }
}
operation JUMP_BACK n ( -- ) {
@@ -1335,9 +1349,7 @@ table normal_byte_codes {
80 = bytecode bc80 {
PREFETCH ();
- STORE_RECEIVER_VARIABLE (arg);
- PUSH_SELF ();
- RETURN_CONTEXT_STACK_TOP ();
+ INVALID (arg);
}
81 = bytecode bc81 {
@@ -1580,8 +1592,7 @@ table normal_byte_codes {
120 = bytecode bc120 {
PREFETCH ();
- STORE_RECEIVER_VARIABLE (arg);
- POP_STACK_TOP ();
+ INVALID (arg);
}
121 = bytecode bc121 {
@@ -2393,8 +2404,7 @@ table normal_byte_codes {
248 = bytecode bc248 {
PREFETCH ();
- STORE_RECEIVER_VARIABLE (arg);
- RETURN_CONTEXT_STACK_TOP ();
+ INVALID (arg);
}
249 = bytecode bc249 {
--
1.8.3.2
_______________________________________________
help-smalltalk mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-smalltalk