Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
v8: fix postmortem metadata generation
The v8 team did some replumbing to the way maps link up to transitions
and object descriptors. This patch fixes the build, but in the future
we'll probably have to add some new fields.
  • Loading branch information
piscisaureus committed Sep 18, 2012
1 parent 51781be commit e72ac8a
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions deps/v8/tools/gen-postmortem-metadata.py
Expand Up @@ -78,14 +78,12 @@
{ 'name': 'SmiValueShift', 'value': 'kSmiTagSize' },
{ 'name': 'PointerSizeLog2', 'value': 'kPointerSizeLog2' },

{ 'name': 'prop_idx_transitions',
'value': 'DescriptorArray::kTransitionsIndex' },
{ 'name': 'prop_idx_first',
'value': 'DescriptorArray::kFirstIndex' },
{ 'name': 'prop_type_field',
'value': 'FIELD' },
{ 'name': 'prop_type_first_phantom',
'value': 'MAP_TRANSITION' },
'value': 'TRANSITION' },
{ 'name': 'prop_type_mask',
'value': 'PropertyDetails::TypeField::kMask' },

Expand All @@ -107,9 +105,9 @@
'JSObject, elements, Object, kElementsOffset',
'FixedArray, data, uintptr_t, kHeaderSize',
'Map, instance_attributes, int, kInstanceAttributesOffset',
'Map, instance_descriptors, int, kInstanceDescriptorsOrBitField3Offset',
'Map, inobject_properties, int, kInObjectPropertiesOffset',
'Map, instance_size, int, kInstanceSizeOffset',
'Map, transitions, int, kTransitionsOrBackPointerOffset',
'HeapNumber, value, double, kValueOffset',
'ConsString, first, String, kFirstOffset',
'ConsString, second, String, kSecondOffset',
Expand Down

3 comments on commit e72ac8a

@piscisaureus
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davepacheco @bcantrill

You probably want to take a look and figure out what fields you need added to keep the ustack helper working.

@bcantrill
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a patch that both corrects gen-postmortem-metadata.py and adds tests for both the postmortem and DTrace support:

diff --git a/deps/v8/tools/gen-postmortem-metadata.py b/deps/v8/tools/gen-postmortem-metadata.py
index 3570f25..3145610 100644
--- a/deps/v8/tools/gen-postmortem-metadata.py
+++ b/deps/v8/tools/gen-postmortem-metadata.py
@@ -78,12 +78,23 @@ consts_misc = [
     { 'name': 'SmiValueShift',          'value': 'kSmiTagSize' },
     { 'name': 'PointerSizeLog2',        'value': 'kPointerSizeLog2' },

+    { 'name': 'transitions_idx_descriptors',
+        'value': 'TransitionArray::kDescriptorsIndex' },
+
+    { 'name': 'prop_desc_key',
+        'value': 'DescriptorArray::kDescriptorKey' },
+    { 'name': 'prop_desc_details',
+        'value': 'DescriptorArray::kDescriptorDetails' },
+    { 'name': 'prop_desc_value',
+        'value': 'DescriptorArray::kDescriptorValue' },
+    { 'name': 'prop_desc_size',
+        'value': 'DescriptorArray::kDescriptorSize' },
     { 'name': 'prop_idx_first',
         'value': 'DescriptorArray::kFirstIndex' },
     { 'name': 'prop_type_field',
         'value': 'FIELD' },
     { 'name': 'prop_type_first_phantom',
-        'value': 'TRANSITION' },
+        'value': 'Code::MAP_TRANSITION' },
     { 'name': 'prop_type_mask',
         'value': 'PropertyDetails::TypeField::kMask' },

@@ -105,9 +116,9 @@ extras_accessors = [
     'JSObject, elements, Object, kElementsOffset',
     'FixedArray, data, uintptr_t, kHeaderSize',
     'Map, instance_attributes, int, kInstanceAttributesOffset',
+    'Map, transitions, uintptr_t, kTransitionsOrBackPointerOffset',
     'Map, inobject_properties, int, kInObjectPropertiesOffset',
     'Map, instance_size, int, kInstanceSizeOffset',
-    'Map, transitions, int, kTransitionsOrBackPointerOffset',
     'HeapNumber, value, double, kValueOffset',
     'ConsString, first, String, kFirstOffset',
     'ConsString, second, String, kSecondOffset',
diff --git a/test/pummel/test-dtrace-jsstack.js b/test/pummel/test-dtrace-jsstack.js
new file mode 100644
index 0000000..6779a76
--- /dev/null
+++ b/test/pummel/test-dtrace-jsstack.js
@@ -0,0 +1,107 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('../common');
+var assert = require('assert');
+var os = require('os');
+var util = require('util');
+
+if (os.type() != 'SunOS') {
+  console.error('Skipping because DTrace not available.');
+  process.exit(0);
+}
+
+/*
+ * Some functions to create a recognizable stack.
+ */
+var frames = [ 'stalloogle', 'bagnoogle', 'doogle' ];
+var expected;
+
+var stalloogle = function (str) {
+  expected = str;
+  os.loadavg();
+};
+
+var bagnoogle = function (arg0, arg1) {
+  stalloogle(arg0 + ' is ' + arg1 + ' except that it is read-only');
+};
+
+var done = false;
+
+var doogle = function () {
+  if (!done)
+    setTimeout(doogle, 10);
+
+  bagnoogle('The bfs command', '(almost) like ed(1)');
+};
+
+var spawn = require('child_process').spawn;
+var prefix = '/var/tmp/node';
+var corefile = prefix + '.' + process.pid;
+
+/*
+ * We're going to use DTrace to stop us, gcore us, and set us running again
+ * when we call getloadavg() -- with the implicit assumption that our
+ * deepest function is the only caller of os.loadavg().
+ */
+var dtrace = spawn('dtrace', [ '-qwn', 'syscall::getloadavg:entry/pid == ' +
+  process.pid + '/{ustack(100, 8192); exit(0); }' ]);
+
+var output = '';
+
+dtrace.stderr.on('data', function (data) {
+  console.log('dtrace: ' + data);
+});
+
+dtrace.stdout.on('data', function (data) {
+  output += data;
+});
+
+dtrace.on('exit', function (code) {
+  if (code != 0) {
+    console.error('dtrace exited with code ' + code);
+    process.exit(code);
+  }
+
+  done = true;
+
+  var sentinel = '(anon) as ';
+  var lines = output.split('\n');
+
+  for (var i = 0; i < lines.length; i++) {
+    var line = lines[i];
+
+    if (line.indexOf(sentinel) == -1 || frames.length === 0)
+      continue;
+
+    var frame = line.substr(line.indexOf(sentinel) + sentinel.length);
+    var top = frames.shift();
+
+    assert.equal(frame.indexOf(top), 0, 'unexpected frame where ' +
+      top + ' was expected');
+  }
+
+  assert.equal(frames.length, 0, 'did not find expected frame ' + frames[0]);
+  process.exit(0);
+});
+
+setTimeout(doogle, 10);
+
diff --git a/test/pummel/test-postmortem-findjsobjects.js b/test/pummel/test-postmortem-findjsobjects.js
new file mode 100644
index 0000000..9b8192f
--- /dev/null
+++ b/test/pummel/test-postmortem-findjsobjects.js
@@ -0,0 +1,99 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('../common');
+var assert = require('assert');
+var os = require('os');
+var util = require('util');
+
+if (os.type() != 'SunOS') {
+  console.error('Skipping because postmortem debugging not available.');
+  process.exit(0);
+}
+
+/*
+ * Now we're going to fork ourselves to gcore 
+ */
+var spawn = require('child_process').spawn;
+var prefix = '/var/tmp/node';
+var corefile = prefix + '.' + process.pid;
+var gcore = spawn('gcore', [ '-o', prefix, process.pid + '' ]);
+var output = '';
+var unlinkSync = require('fs').unlinkSync;
+var args = [ corefile ];
+
+if (process.env.MDB_LIBRARY_PATH && process.env.MDB_LIBRARY_PATH != '')
+  args = args.concat([ '-L', process.env.MDB_LIBRARY_PATH ]);
+
+function LanguageH(chapter) { this.OBEY = 'CHAPTER ' + parseInt(chapter, 10); }
+var obj = new LanguageH(1);
+
+gcore.stderr.on('data', function (data) {
+  console.log('gcore: ' + data);
+});
+
+gcore.on('exit', function (code) {
+  if (code != 0) {
+    console.error('gcore exited with code ' + code);
+    process.exit(code);
+  }
+
+  var mdb = spawn('mdb', args, { stdio: 'pipe' });
+
+  mdb.on('exit', function (code) {
+    var retained = '; core retained as ' + corefile;
+
+    if (code != 0) {
+      console.error('mdb exited with code ' + util.inspect(code) + retained);
+      process.exit(code);
+    }
+
+    var lines = output.split('\n');
+    var found = 0, i, expected = 'OBEY: ' + obj.OBEY, nexpected = 2;
+
+    for (var i = 0; i < lines.length; i++) {
+      if (lines[i].indexOf(expected) != -1)
+        found++;
+    }
+
+    assert.equal(found, nexpected, 'expected ' + nexpected +
+      ' objects, found ' + found + retained);
+
+    unlinkSync(corefile);
+    process.exit(0);
+  });
+
+  mdb.stdout.on('data', function (data) {
+    output += data;
+  });
+
+  mdb.stderr.on('data', function (data) {
+    console.log('mdb stderr: ' + data);
+  });
+
+  mdb.stdin.write('::load v8.so\n');
+  mdb.stdin.write('::findjsobjects -c LanguageH | ');
+  mdb.stdin.write('::findjsobjects | ::jsprint\n');
+  mdb.stdin.write('::findjsobjects -p OBEY | ');
+  mdb.stdin.write('::findjsobjects | ::jsprint\n');
+  mdb.stdin.end();
+});
+
diff --git a/test/pummel/test-postmortem-jsstack.js b/test/pummel/test-postmortem-jsstack.js
new file mode 100644
index 0000000..58d711b
--- /dev/null
+++ b/test/pummel/test-postmortem-jsstack.js
@@ -0,0 +1,179 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('../common');
+var assert = require('assert');
+var os = require('os');
+var util = require('util');
+
+if (os.type() != 'SunOS') {
+  console.error('Skipping because postmortem debugging not available.');
+  process.exit(0);
+}
+
+/*
+ * Some functions to create a recognizable stack.
+ */
+var frames = [ 'stalloogle', 'bagnoogle', 'doogle' ];
+var expected;
+
+var stalloogle = function (str) {
+  expected = str;
+  os.loadavg();
+};
+
+var bagnoogle = function (arg0, arg1) {
+  stalloogle(arg0 + ' is ' + arg1 + ' except that it is read-only');
+};
+
+var done = false;
+
+var doogle = function () {
+  if (!done)
+    setTimeout(doogle, 10);
+
+  bagnoogle('The bfs command', '(almost) like ed(1)');
+};
+
+var spawn = require('child_process').spawn;
+var prefix = '/var/tmp/node';
+var corefile = prefix + '.' + process.pid;
+var args = [ corefile ];
+
+if (process.env.MDB_LIBRARY_PATH && process.env.MDB_LIBRARY_PATH != '')
+  args = args.concat([ '-L', process.env.MDB_LIBRARY_PATH ]);
+
+/*
+ * We're going to use DTrace to stop us, gcore us, and set us running again
+ * when we call getloadavg() -- with the implicit assumption that our
+ * deepest function is the only caller of os.loadavg().
+ */
+var dtrace = spawn('dtrace', [ '-qwn', 'syscall::getloadavg:entry/pid == ' +
+  process.pid + '/{stop(); system("gcore -o ' +
+  prefix + ' %d", pid); system("prun %d", pid); exit(0); }' ]);
+
+var output = '';
+var unlinkSync = require('fs').unlinkSync;
+
+dtrace.stderr.on('data', function (data) {
+  console.log('dtrace: ' + data);
+});
+
+dtrace.on('exit', function (code) {
+  if (code != 0) {
+    console.error('dtrace exited with code ' + code);
+    process.exit(code);
+  }
+
+  done = true;
+
+  /*
+   * We have our core file.  Now we need to fire up mdb to analyze it...
+   */
+  var mdb = spawn('mdb', args, { stdio: 'pipe' });
+
+  mdb.on('exit', function (code) {
+    var retained = '; core retained as ' + corefile;
+
+    if (code != 0) {
+      console.error('mdb exited with code ' + code + retained);
+      process.exit(code);
+    }
+
+    var sentinel = '<anonymous> (as ';
+    var arg1 = '    arg1: ';
+    var lines = output.split('\n');
+    var matched = 0;
+    var straddr = undefined;
+
+    for (var i = 0; i < lines.length; i++) {
+      var line = lines[i];
+
+      if (matched == 1 && line.indexOf(arg1) === 0) {
+        straddr = line.substr(arg1.length).split(' ')[0];
+      }
+
+      if (line.indexOf(sentinel) == -1 || frames.length === 0)
+        continue;
+
+      var frame = line.substr(line.indexOf(sentinel) + sentinel.length);
+      var top = frames.shift();
+
+      assert.equal(frame.indexOf(top), 0, 'unexpected frame where ' +
+        top + ' was expected' + retained);
+
+      matched++;
+    }
+
+    assert.equal(frames.length, 0, 'did not find expected frame ' +
+      frames[0] + retained);
+
+    assert.notEqual(straddr, undefined,
+      'did not find arg1 for top frame' + retained);
+
+    /*
+     * Now we're going to take one more swing at the core file to print out
+     * the argument string that we found.
+     */
+    output = '';
+    mdb = spawn('mdb', args, { stdio: 'pipe' });
+ 
+    mdb.on('exit', function (code) {
+      if (code != 0) {
+        console.error('mdb (second) exited with code ' + code + retained);
+        process.exit(code);
+      }
+
+      assert.notEqual(output.indexOf(expected), -1, 'did not find arg1 (' +
+        straddr + ') to contain expected string' + retained);
+
+      unlinkSync(corefile);
+      process.exit(0);
+    });
+
+    mdb.stdout.on('data', function (data) {
+      output += data;
+    });
+
+    mdb.stderr.on('data', function (data) {
+      console.log('mdb (second) stderr: ' + data);
+    });
+
+    mdb.stdin.write('::load v8.so\n');
+    mdb.stdin.write(straddr + '::v8str\n');
+    mdb.stdin.end();
+  });
+
+  mdb.stdout.on('data', function (data) {
+    output += data;
+  });
+
+  mdb.stderr.on('data', function (data) {
+    console.log('mdb stderr: ' + data);
+  });
+
+  mdb.stdin.write('::load v8.so\n');
+  mdb.stdin.write('::jsstack -v\n');
+  mdb.stdin.end();
+});
+
+setTimeout(doogle, 10);
+

@piscisaureus
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bcantrill
Thanks, landed in cc1b09d and 017009f. I can't send the v8 patch upstream now because it doesn't work with v8 trunk; you should probably take a look again after the dust has settled in v8.

Please sign in to comment.