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

Code cache is rejected if it's size is under about 8K #4939

Closed
ehjoon opened this issue Jan 29, 2016 · 2 comments
Closed

Code cache is rejected if it's size is under about 8K #4939

ehjoon opened this issue Jan 29, 2016 · 2 comments
Labels
v8 engine Issues and PRs related to the V8 dependency.

Comments

@ehjoon
Copy link

ehjoon commented Jan 29, 2016

I tested this patch. I found strange thing. I load cached data from file and reuse it when node process restart. The problem is that the cache data which size is under 8K is always rejected with sanity check error 'MAGIC_NUMBER_MISMATCH'. cached_data_buf from GetCachedData is wrong completly.

Code : 96934cb

create_cache.js

const vm = require('vm');
const fs = require('fs');

const testData = fs.readFileSync('./test.js');
testScript = new vm.Script(testData, { produceCachedData: true });
fs.writeFileSync('/tmp/test.js.code_cache', testScript.cachedData);

use_cache.js

const vm = require('vm');
const fs = require('fs');

testObj = { one: 'one', two : 'two', result: false };

testData = fs.readFileSync('./test.js');
testCache = fs.readFileSync('/tmp/test.js.code_cache');
var testScript = new vm.Script(testData, { cachedData: testCache });

if ( testScript.cachedDataRejected == true ) console.log('test Cache data is rejected');

testScript.runInThisContext();

console.log('testObj.result = ' + testObj.result);

cat test.js

testObj.result = true;

Test Result

~/code_cache_test_analyze # /node create_cache.js
~/code_cache_test_analyze # /node use_cache.js
test Cache data is rejected
testObj.result = true
~/code_cache_test_analyze # hexdump /tmp/test.js.code_cache
0000000 054c c0de 53fb 1175 0017 0000 ec00 0006
0000010 8731 3547 0005 0000 0002 0000 0284 0000
0000020 2a95 2d31 65f 0288 0034 8000 016c 8000
0000030 0120 8000 0000 8000 0000 8000 0091 0000
0000040 0023 0000 6001 8a8f 2102 9f01 2401 d780
0000050 0036 0000 0000 2800 4b18 52fe 6130 2210
0000060 3132 3d00 3012 1021 0201 2202 0181 0002
0000070 9c18 9c18 1001 f118 d204 0004 0000 0000
0000080 0000 0000 0000 5785 0421 0000 0000 00dc
0000090 0000 0000 0000 0030 0000 0004 0000 006c
00000a0 0000 0000 0000 0000 0000 0000 0000 0000
00000b0 0000 4882 e92d c00c e1a0 b008 e28d 9014
00000c0 e59a 9004 e52d c50c e59a 000c e15d 0001
00000d0 2a00 c08c e59f ff3c e12f 1013 e597 2084
00000e0 e59f 0006 e3a0 c080 e59f ff3c e12f 0004
00000f0 e52d 0078 e59f 2078 e59f 1004 e49d 400a
0000100 e3a0 c070 e59f ff3c e12f 000c e50b 000c
0000110 e51b 2064 e59f 3003 e592 305e e253 3003
0000120 e582 0008 5a00 0004 e52d c050 e59f ff3c
0000130 e12f 0004 e49d 2048 e59f 0000 e1a0 0000
0000140 e1a0 3a03 e3a0 3003 e582 d00b e1a0 4800
0000150 e8bd d004 e28d ff1e e12f 0014 e59a ffeb
0000160 eaff 00f9 e7f0 0000 0000 0000 0000 0000
0000170 0000 0000 0000 0000 0000 0000 0000 0000
*
0000190 0000 711d 7c03 0145 1401 9418 a6d3 3d7f
00001a0 0e3f 0000 7400 7365 4f74 6a62 7b00 8804
00001b0 1401 9418 8ad3 79cf 0c4c 0000 7200 7365
00001c0 6c75 0074 7b00 0108 8d08 00d0 0030 7c00
00001d0 013d bc09 201d 00d0 0000 0100 1828 d780
00001e0 0010 0000 0106 0000 0000 0000 0002 0000
00001f0 0000 0000 0000 0000 0000 0000 0000 0000
0000200 c518 1c02 189c 0365 0185 1840 04dd 001b
0000210 2400 9018 03d7 0000 2e00 0000 6500 6176
0000220 6d6c 6361 6968 656e 3c2e 6e61 6e6f 6d79
0000230 756f 3e73 d175 0000 0000 0000 0000 f085
0000240 04d0 0000 8500 72d0 0000 8500 00d0 0000
0000250 0000 9e10 04d1 0000 0000 0000 0100 180c
0000260 098c 8600 04d0 0000 8500 85f0 018a 9e24
0000270 0ed0 0000 0100 9e10 04d2 0000 0800 0000
0000280 0400 0002 d100 0000 0000 0000 0000 8d18
0000290 f104 dbf0 0000 0000 0000 0000 0014 0000
00002a0 0000 0000 0006 0000 002e 0000 fffe ffff
00002b0 1006 0000 0000 0000 0000 0000 0014 0000
00002c0 0000 0000 3d17 3d3d
00002c8
~/code_cache_test_analyze #
@mscdex
Copy link
Contributor

mscdex commented Jan 29, 2016

/cc @indutny

@mscdex mscdex added the v8 engine Issues and PRs related to the V8 dependency. label Jan 29, 2016
indutny added a commit to indutny/io.js that referenced this issue Jan 29, 2016
Do not blindly take data from underlying `ArrayBuffer`, use
`ByteOffset`/`ByteLength` of `Uint8Array` itself.

Additionally, fix tests that weren't actually properly running because
of V8's internal code cache. The code should be different, otherwise the
cached data won't be used at all.

Fix: nodejs#4939
@indutny
Copy link
Member

indutny commented Jan 29, 2016

Should be fixed by #4947

rvagg pushed a commit that referenced this issue Feb 10, 2016
Do not blindly take data from underlying `ArrayBuffer`, use
`ByteOffset`/`ByteLength` of `Uint8Array` itself.

Additionally, fix tests that weren't actually properly running because
of V8's internal code cache. The code should be different, otherwise the
cached data won't be used at all.

Fix: #4939
PR-URL: #4947
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
scovetta pushed a commit to scovetta/node that referenced this issue Apr 2, 2016
Do not blindly take data from underlying `ArrayBuffer`, use
`ByteOffset`/`ByteLength` of `Uint8Array` itself.

Additionally, fix tests that weren't actually properly running because
of V8's internal code cache. The code should be different, otherwise the
cached data won't be used at all.

Fix: nodejs#4939
PR-URL: nodejs#4947
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 engine Issues and PRs related to the V8 dependency.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants