git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 1ee5f08dcf25af27f0dce6fdc1eab39b185d202f

move storage to hypervisor layer

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 3/1/2018, 1:16:34 AM
Parent: d291bade737857a6cb2a21c8505c308c7a61a90e

Files changed

actor.jschanged
index.jschanged
wasmContainer.jschanged
actor.jsView
@@ -31,10 +31,13 @@
3131 /**
3232 * Runs the shutdown routine for the actor
3333 */
3434 async shutdown () {
35- await this.state.done()
36- this.state.root['/'][3] = this.serializeMetaData()
35+ await this.tree.set(this.id.id, this.serializeMetaData())
36+ if (this.storage.length) {
37+ const state = await this.tree.get(this.id.id)
38+ return this.tree.graph.set(state.root, '2', this.storage)
39+ }
3740 }
3841
3942 /**
4043 * Runs the startup routine for the actor
index.jsView
@@ -29,12 +29,12 @@
2929 this.scheduler.queue(messages)
3030 }
3131
3232 async loadActor (id) {
33- const state = await this.tree.getSubTree(id.id)
34- const state2 = await this.tree.get(id.id, true)
35- let code = await this.tree.graph.get(state2.root, '1')
36- const {type, nonce} = Actor.deserializeMetaData(state2.value)
33+ const state = await this.tree.get(id.id, true)
34+ let code = await this.tree.graph.get(state.root, '1')
35+ let storage = await this.tree.graph.get(state.root, '2')
36+ const {type, nonce} = Actor.deserializeMetaData(state.value)
3737 const Container = this._containerTypes[type]
3838
3939 // create a new actor instance
4040 const actor = new Actor({
@@ -44,9 +44,11 @@
4444 id,
4545 nonce,
4646 type,
4747 code,
48- cachedb: this.tree.dag._dag
48+ storage: storage || [],
49+ cachedb: this.tree.dag._dag,
50+ tree: this.tree
4951 })
5052
5153 await actor.startup()
5254 return actor
wasmContainer.jsView
@@ -73,14 +73,8 @@
7373 // initialize the globals
7474 let numOfGlobals = json.globals.length
7575 if (numOfGlobals) {
7676 moduleJSON = injectGlobals(moduleJSON, json.globals)
77- const storage = []
78- while (numOfGlobals--) {
79- const type = json.globals[numOfGlobals].type
80- storage.push(DEFAULTS[type])
81- }
82- tree.set(Buffer.concat([id.id, Buffer.from([1])]), storage)
8377 }
8478 // recompile the wasm
8579 wasm = json2wasm(moduleJSON)
8680 await Promise.all([
@@ -221,9 +215,9 @@
221215 let numOfGlobals = this.json.globals.length
222216 if (numOfGlobals) {
223217 const refs = []
224218 while (numOfGlobals--) {
225- const obj = this.storage[numOfGlobals]
219+ const obj = this.actor.storage[numOfGlobals] || DEFAULTS[this.json.globals[numOfGlobals].type]
226220 refs.push(this.refs.add(obj, this.json.globals[numOfGlobals].type))
227221 }
228222 this.instance.exports.setter_globals(...refs)
229223 }
@@ -237,16 +231,15 @@
237231 await this.onDone()
238232
239233 numOfGlobals = this.json.globals.length
240234 if (numOfGlobals) {
241- this.storage = []
235+ this.actor.storage = []
242236 this.instance.exports.getter_globals()
243237 const mem = new Uint32Array(this.instance.exports.memory.buffer, 0, numOfGlobals)
244238 while (numOfGlobals--) {
245239 const ref = mem[numOfGlobals]
246- this.storage.push(this.refs.get(ref, this.json.globals[numOfGlobals].type))
240+ this.actor.storage.push(this.refs.get(ref, this.json.globals[numOfGlobals].type))
247241 }
248- this.actor.state.set(Buffer.from([1]), this.storage)
249242 }
250243
251244 this.refs.clear()
252245 }
@@ -273,9 +266,9 @@
273266 return this._opsQueue
274267 }
275268
276269 async onStartup () {
277- let [json, wasm, storage] = await Promise.all([
270+ let [json, wasm] = await Promise.all([
278271 new Promise((resolve, reject) => {
279272 this.actor.cachedb.get(this.actor.id.id.toString() + 'meta', (err, json) => {
280273 if (err) {
281274 reject(err)
@@ -291,12 +284,10 @@
291284 } else {
292285 resolve(wasm)
293286 }
294287 })
295- }),
296- this.actor.state.get(Buffer.from([1]))
288+ })
297289 ])
298- this.storage = storage.value
299290 wasm = Buffer.from(wasm, 'hex')
300291 json = JSON.parse(json)
301292 this.mod = WebAssembly.Module(wasm)
302293 this.json = json

Built with git-ssb-web