Source

jsprobes-patches / add-jsprobes-core-definitions

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
# HG changeset patch
# Parent 799e0e4a64d5fdf9cbee91a8dba41b8ae9c8d016
Add the jsprobes.tbl data, as well as core structs in jsprobedefs.h such as ProbeType, ProbeValue, and other useful data.

diff --git a/js/src/Makefile.in b/js/src/Makefile.in
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -134,6 +134,7 @@
 		jsopcode.cpp \
 		jsproxy.cpp \
 		jsprf.cpp \
+		jsprobedefs.cpp \
 		jsprobes.cpp \
 		jspropertycache.cpp \
 		jspropertytree.cpp \
@@ -200,6 +201,8 @@
 		json.h \
 		jsproxy.h \
 		jsprf.h \
+		jsprobedefs.h \
+		jsprobes.tbl \
 		jsproto.tbl \
 		jsprvtd.h \
 		jspubtd.h \
diff --git a/js/src/jsprobedefs.cpp b/js/src/jsprobedefs.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jsprobedefs.cpp
@@ -0,0 +1,255 @@
+/* -*- Mode: c++; c-basic-offset: 4; tab-width: 40; indent-tabs-mode: nil -*- */
+/* vim: set ts=40 sw=4 et tw=99: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Mozilla jsprobes library
+ *
+ * The Initial Developer of the Original Code is
+ *   Mozilla Foundation
+ *
+ * Contributor(s):
+ *   Brian J. Burg <burg@cs.washington.edu>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include <prtime.h>
+
+#include "jsscript.h"
+#include "jscntxt.h"
+#include "jscompartment.h"
+#include "jsprobedefs.h"
+
+namespace js {
+namespace probes {
+    
+const ProbeTypeSpec ProbeTypeData[] = {
+#define PROBE_TYPE(ctype, tyname, id, isleaf, reifyFn)                         \
+    { ProbeType_ ## tyname, #tyname, sizeof(ctype), isleaf, reifyFn }, 
+#include "jsprobes.tbl"
+#undef PROBE_TYPE
+};
+
+
+/*
+  This bit of macrology generates (example) entries of the form:
+  
+    { JS_RUNTIME_CREATE,  0, (ProbeType[]){ { runtime, ProbeType_JSRuntimePtr } } },
+    { JS_RUNTIME_DESTROY, 1, (ProbeType[]){ { runtime, ProbeType_JSRuntimePtr },
+                                            { size,    ProbeType_size_t } } }
+                    
+    Note that this uses cast constructors, but doesn't specify element
+    size. Tis is to allow for argc to be zero, but still be able to
+    write a struct initializer (with dummy arguments). This is
+    probably not portable outside of GCC/clang, but have no evidence
+    either way.
+
+    (http://tigcc.ticalc.org/doc/gnuexts.html#SEC81)
+*/
+
+const ProbePointSpec ProbePointData[] = {
+#define PROBE_POINT(name, num, str, argc, argspeclist)                         \
+    { name, #name, argc, (ProbePointArgSpec[])argspeclist },
+#include "jsprobes.tbl"
+#undef PROBE_POINT
+};
+
+const ProbeTransformSpec ProbeFunctionData[] = {
+#define PROBE_TRANS(fn, apiname, id, in, out)                                  \
+    { ProbeTransform_ ## fn, #fn, #apiname, fn, &ProbeTypeData[ProbeType_ ## in], &ProbeTypeData[ProbeType_ ## out] },
+#include "jsprobes.tbl"
+#undef PROBE_TRANS
+};
+
+ProbeValue::ProbeValue(ProbeType aType)
+    : ty(aType) { }
+
+ProbeValue::ProbeValue(ProbeType aType, void *aThing)
+    : ty(aType) {
+    /* special case: aThing is NULL, so just zero out the bytes
+       allocated for this ProbeType */
+    if (!aThing)
+        memset(&data, 0, ProbeTypeData[ty].bytes);
+    else
+        memcpy(&data, aThing, ProbeTypeData[ty].bytes);
+}
+
+bool
+ProbeValue::serialize(void *bufp)
+{
+    JS_ASSERT(ProbeTypeData[ty].isLeaf);
+ 
+    memcpy(bufp, &data, ProbeTypeData[ty].bytes);
+    bufp = ((char*)bufp) + ProbeTypeData[ty].bytes;
+    return true;
+}
+
+js::Value
+ProbeValue::deserialize(JSContext *cx, ProbeType ty, void *bufp)
+{
+    JS_ASSERT(ProbeTypeData[ty].isLeaf);
+    JS_ASSERT(ProbeTypeData[ty].reifyFn);
+
+    ProbeValue tempVal = ProbeValue(ty, bufp);
+    return (ProbeTypeData[ty].reifyFn)(cx, tempVal);
+}
+
+
+/* The following are library functions for converting between
+ * different ProbeValues. Right now, transforms follow the JS API
+ * (expected) naming convention, instead of the ctypes naming covention. */
+
+#define PROBE_VALUE_SET(arg, newty, expr)                                      \
+    do {                                                                       \
+        arg->data.as_ ## newty = expr;                                         \
+        arg->ty = ProbeType_ ## newty;                                         \
+    } while (0)
+
+
+bool
+runtime_gcBytes(JSRuntime *rt, ProbeValue *arg)
+{
+    JS_ASSERT(arg);
+    JS_ASSERT(arg->ty == ProbeType_JSRuntimePtr);
+    JS_ASSERT(arg->data.as_JSRuntimePtr);
+    PROBE_VALUE_SET(arg, size_t, arg->data.as_JSRuntimePtr->gcBytes);
+    return true;
+}
+
+bool
+runtime_gcMaxBytes(JSRuntime *rt, ProbeValue *arg)
+{
+    JS_ASSERT(arg);
+    JS_ASSERT(arg->ty == ProbeType_JSRuntimePtr);
+    JS_ASSERT(arg->data.as_JSRuntimePtr);
+    PROBE_VALUE_SET(arg, size_t, arg->data.as_JSRuntimePtr->gcMaxBytes);
+    return true;
+}
+
+bool
+runtime_gcMaxMallocBytes(JSRuntime *rt, ProbeValue *arg)
+{
+    JS_ASSERT(arg);
+    JS_ASSERT(arg->ty == ProbeType_JSRuntimePtr);
+    JS_ASSERT(arg->data.as_JSRuntimePtr);
+    PROBE_VALUE_SET(arg, size_t, arg->data.as_JSRuntimePtr->gcMaxMallocBytes);
+    return true;
+}
+
+bool
+compartment_runtime(JSRuntime *rt, ProbeValue *arg)
+{
+    JS_ASSERT(arg);
+    JS_ASSERT(arg->ty == ProbeType_JSCompartmentPtr);
+    JS_ASSERT(arg->data.as_JSCompartmentPtr);
+    PROBE_VALUE_SET(arg, JSRuntimePtr, arg->data.as_JSCompartmentPtr->rt);
+    return true;
+}
+
+bool
+compartment_gcBytes(JSRuntime *rt, ProbeValue *arg)
+{
+    JS_ASSERT(arg);
+    JS_ASSERT(arg->ty == ProbeType_JSCompartmentPtr);
+    JS_ASSERT(arg->data.as_JSCompartmentPtr);
+    PROBE_VALUE_SET(arg, size_t, arg->data.as_JSCompartmentPtr->gcBytes);
+    return true;
+}
+
+bool
+compartment_gcTriggerBytes(JSRuntime *rt, ProbeValue *arg)
+{
+    JS_ASSERT(arg);
+    JS_ASSERT(arg->ty == ProbeType_JSCompartmentPtr);
+    JS_ASSERT(arg->data.as_JSCompartmentPtr);
+    PROBE_VALUE_SET(arg, size_t, arg->data.as_JSCompartmentPtr->gcTriggerBytes);
+    return true;
+}
+
+bool
+compartment_id(JSRuntime *rt, ProbeValue *arg)
+{
+    JS_ASSERT(arg);
+    JS_ASSERT(arg->ty == ProbeType_JSCompartmentPtr);
+    JS_ASSERT(arg->data.as_JSCompartmentPtr);
+    PROBE_VALUE_SET(arg, intptr_t, (intptr_t)arg->data.as_JSCompartmentPtr);
+    return true;
+}
+
+bool
+env_currentTimeMS(JSRuntime *rt, ProbeValue *arg)
+{
+    JS_ASSERT(arg->ty == ProbeType_DummyGlobal);
+    PROBE_VALUE_SET(arg, double, (double)(PR_Now()/PR_USEC_PER_MSEC));
+    return true;
+}
+
+js::Value
+deserialize_size_t(JSContext *cx, ProbeValue v)
+{
+    return js::DoubleValue((double)v.data.as_size_t);
+}
+
+js::Value
+deserialize_intptr_t(JSContext *cx, ProbeValue v)
+{
+    return js::DoubleValue((double)v.data.as_intptr_t);
+}
+
+js::Value
+deserialize_int(JSContext *cx, ProbeValue v)
+{
+    if (sizeof(int) != sizeof(int32))
+        return js::DoubleValue((double)v.data.as_int);
+    else
+        return js::Int32Value(v.data.as_int);
+}
+
+js::Value
+deserialize_double(JSContext *cx, ProbeValue v)
+{
+    return js::DoubleValue(v.data.as_double);
+}
+
+js::Value
+deserialize_OwnedSCBufferPtr(JSContext *cx, ProbeValue v)
+{
+    /* TODO: use structured clone, free buf after use */
+
+    return JSVAL_TRUE;
+}
+
+js::Value
+deserialize_OwnedConstCharPtr(JSContext *cx, ProbeValue v)
+{
+    const char *oldStr = v.data.as_OwnedConstCharPtr;
+    JSString *newStr = JS_NewStringCopyN(cx, oldStr, sizeof(oldStr));
+    JS_free(cx, const_cast<char*>(oldStr));
+
+    return (newStr) ? js::StringValue(newStr) : js::UndefinedValue();
+}
+
+}
+}
diff --git a/js/src/jsprobedefs.h b/js/src/jsprobedefs.h
new file mode 100644
--- /dev/null
+++ b/js/src/jsprobedefs.h
@@ -0,0 +1,168 @@
+/* -*- Mode: c++; c-basic-offset: 4; tab-width: 40; indent-tabs-mode: nil -*- */
+/* vim: set ts=40 sw=4 et tw=99: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Mozilla jsprobes library
+ *
+ * The Initial Developer of the Original Code is
+ *   Mozilla Foundation
+ *
+ * Contributor(s):
+ *   Brian J. Burg <burg@cs.washington.edu>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef _JSPROBEDEFS_H
+#define _JSPROBEDEFS_H
+
+#include "jsapi.h"
+
+namespace js {
+namespace probes {
+
+struct ProbeValue;
+
+typedef js::Value (* JSProbesDeserializeFun)(JSContext *cx, ProbeValue v);
+typedef bool (* JSProbesTransformFun)(JSRuntime *rt, ProbeValue *v);
+
+/* Define the enums ProbePoint, ProbeType, ProbeTransform. The values of
+ * the latter two enums are prepended with ProbeType_ and
+ * ProbeTransform_, respectively. 
+ * 
+ * N.B. the *_Final values are useful for iterating through the enum,
+ * but are not otherwise used.  */
+
+typedef enum {
+#define PROBE_TYPE(ctype, tyname, id, isleaf, reifyFn)                         \
+    ProbeType_ ## tyname  = id,
+#include "jsprobes.tbl"
+#undef PROBE_TYPE
+    ProbeType_Final
+} ProbeType;
+
+typedef enum {
+#define PROBE_POINT(name, num, str, argc, arginfo)                             \
+      name = num,
+#include "jsprobes.tbl"
+#undef PROBE_POINT
+    ProbePoint_Final
+} ProbePoint;
+
+typedef enum {
+#define PROBE_TRANS(fn, apiname, id, in, out)                                  \
+    ProbeTransform_ ## fn = id,
+#include "jsprobes.tbl"
+#undef PROBE_TRANS
+    ProbeTransform_Final
+} ProbeTransform;
+
+struct ProbeTypeSpec;
+struct ProbePointSpec;
+struct ProbePointArgSpec;
+struct ProbeTransformSpec;
+
+extern const ProbeTypeSpec ProbeTypeData[];
+extern const ProbePointSpec ProbePointData[];
+extern const ProbeTransformSpec ProbeFunctionData[];
+
+struct ProbeValue {
+    ProbeType ty;
+    union {
+
+/* This produces entries of the form:
+
+        JSRuntime *as_JSRuntimePtr;
+        size_t as_size_t;
+
+   based on the declared ctype and tyname of each probe type as in the
+   PROBE_TYPE table of jsprobes.tbl */
+
+#define PROBE_TYPE(ctype, tyname, id, isleaf, reifyfn)                         \
+        ctype as_ ## tyname;
+#include "jsprobes.tbl"
+#undef PROBE_TYPE
+    } data;
+
+    ProbeValue(ProbeType ty);
+    ProbeValue(ProbeType ty, void *thing);
+    bool serialize(void *bufp);
+    static js::Value deserialize(JSContext *cx, ProbeType ty, void *bufp);
+};
+
+struct ProbeTypeSpec {
+    const ProbeType type;
+    const char *name;
+    const size_t bytes;
+    const bool isLeaf;
+    const JSProbesDeserializeFun reifyFn;
+};
+
+struct ProbePointSpec {
+    const ProbePoint point;
+    const char *name;
+    const int argc;
+    /* this is an array of length argc */
+    const ProbePointArgSpec *args;
+};
+
+/* this describes the type and JS name for one probe point argument.
+   (this is the equivalent of the 'apiname' field for transforms, but
+   it may be different per probe, say, if several arguments have the
+   same type)
+*/
+struct ProbePointArgSpec {
+    const char *name;
+    const ProbeType type;
+};
+
+struct ProbeTransformSpec {
+    const ProbeTransform transform;
+    const char *fn_name;
+    const char *api_name;
+    const JSProbesTransformFun fn;
+    const ProbeTypeSpec *in_type;
+    const ProbeTypeSpec *out_type;
+};
+
+bool runtime_gcBytes(JSRuntime *rt, ProbeValue *val);
+bool runtime_gcMaxBytes(JSRuntime *rt, ProbeValue *val);
+bool runtime_gcMaxMallocBytes(JSRuntime *rt, ProbeValue *val);
+bool compartment_runtime(JSRuntime *rt, ProbeValue *val);
+bool compartment_gcBytes(JSRuntime *rt, ProbeValue *val);
+bool compartment_gcTriggerBytes(JSRuntime *rt, ProbeValue *val);
+bool compartment_id(JSRuntime *rt, ProbeValue *val);
+bool env_currentTimeMS(JSRuntime *rt, ProbeValue *val);
+
+js::Value deserialize_size_t(JSContext *cx, ProbeValue val);
+js::Value deserialize_intptr_t(JSContext *cx, ProbeValue val);
+js::Value deserialize_int(JSContext *cx, ProbeValue val);
+js::Value deserialize_double(JSContext *cx, ProbeValue val);
+js::Value deserialize_OwnedSCBufferPtr(JSContext *cx, ProbeValue val);    
+js::Value deserialize_OwnedConstCharPtr(JSContext *cx, ProbeValue val);
+    
+}
+}
+#endif /* _JSPROBEDEFS_H */
diff --git a/js/src/jsprobes.tbl b/js/src/jsprobes.tbl
new file mode 100644
--- /dev/null
+++ b/js/src/jsprobes.tbl
@@ -0,0 +1,229 @@
+/* -*- Mode: c++; c-basic-offset: 4; tab-width: 40; indent-tabs-mode: nil -*- */
+/* vim: set ts=40 sw=4 et tw=99: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Mozilla jsprobes library
+ *
+ * The Initial Developer of the Original Code is
+ *   Mozilla Foundation
+ *
+ * Contributor(s):
+ *   Brian J. Burg <burg@cs.washington.edu>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/* Make sure that each macro is defined (even if trivially). This is 
+   a cheap trick to be able to have all three tables in the same file. */
+
+#ifndef PROBE_POINT
+#define _PROBE_POINT_DEFAULTED
+#define PROBE_POINT(a,b,c,d,e)
+#endif
+
+#ifndef PROBE_TYPE
+#define _PROBE_TYPE_DEFAULTED
+#define PROBE_TYPE(a,b,c,d,e)
+#endif
+
+#ifndef PROBE_TRANS
+#define _PROBE_TRANS_DEFAULTED
+#define PROBE_TRANS(a,b,c,d,e)
+#endif
+
+
+/* Helpers to make PROBE_POINT entries shorter */
+
+#define _ARG(name, ty)                                                         \
+    { #name, ProbeType_ ## ty }
+#define _ARG_1(a)                                                              \
+    { a }
+#define _ARG_2(a,b)                                                            \
+    { a, b }
+#define _ARG_3(a,b,c)                                                          \
+    { a, b, c }
+#define _ARG_4(a,b,c,d)                                                        \
+    { a, b, c, d }
+
+#define _NO_ARGS _ARG_1(_ARG(dummy, None))
+
+/* This table defines the C data types that a ProbeValue can possibly
+ * represent. Included is their ctype name, ProbeType enum name, id,
+ * and a reifying function that can covert from ProbeValue to js::Value.
+ * It is used to define the ProbeTypeData and ProbeTransformData arrays.
+ * 
+ *  Includers must define a PROBE_TYPE macro of the following form:
+ * 
+ * #define PROBE_TYPE(ctype,tyname,id,isleaf,reifyfn) ...
+ */
+
+/* legend:  ctype,         tyname,                 id,  isleaf,   reifyfn  */
+
+PROBE_TYPE(int,            None,                    0,  false,    NULL)
+PROBE_TYPE(JSCompartment*, JSCompartmentPtr,        1,  false,    NULL)
+PROBE_TYPE(JSContext*,     JSContextPtr,            2,  false,    NULL)
+PROBE_TYPE(JSFunction*,    JSFunctionPtr,           3,  false,    NULL)
+PROBE_TYPE(JSObject*,      JSObjectPtr,             4,  false,    NULL)
+PROBE_TYPE(JSRuntime*,     JSRuntimePtr,            5,  false,    NULL)
+PROBE_TYPE(JSScript*,      JSScriptPtr,             6,  false,    NULL)
+PROBE_TYPE(JSString*,      JSStringPtr,             7,  false,    NULL)
+
+PROBE_TYPE(const char*,    ConstCharPtr,            8,  false,    NULL)
+PROBE_TYPE(void*,          VoidPtr,                 9,  false,    NULL)
+
+PROBE_TYPE(size_t,         size_t,                 10,   true,    deserialize_size_t)
+PROBE_TYPE(int,            int,                    11,   true,    deserialize_int)
+PROBE_TYPE(double,         double,                 12,   true,    deserialize_double)
+PROBE_TYPE(intptr_t,       intptr_t,               13,   true,    deserialize_intptr_t)
+PROBE_TYPE(void*,          OwnedSCBufferPtr,       14,   true,    deserialize_OwnedSCBufferPtr)
+PROBE_TYPE(const char*,    OwnedConstCharPtr,      15,   true,    deserialize_OwnedConstCharPtr)
+PROBE_TYPE(int,            DummyGlobal,            16,  false,    NULL)
+
+/* This table defines the names, id, arity, and argument names/types
+ * of instrumentation points (henceforth, probe points) throughout the
+ * SpiderMonkey C++ code. It is used to automatically generate debug
+ * messages, the ProbePoint enum.
+ * 
+ *  Includers must define a PROBE_POINT macro of the following form:
+ * 
+ * #define PROBE_POINT(pname,num,sname,argc,arginfo) ...
+ *
+ * N.B. The arginfo argument returns struct initializers for the
+ * ProbePointArgSpec struct type. This is a pair of <char*,
+ * ProbeType>.  string literal quoting and probe type prefixes are
+ * added by the _ARG macro.
+ * 
+ * Due to the limits of C preprocessor macros, pretty much the only
+ * way to access probe point argument names/types is by initializing
+ * such a struct and pulling data out of it.
+ */
+
+/* legend:  probename              num    strname                 argc,  arginfo(name, ty)   */
+PROBE_POINT(GLOBAL_PROBE_ARGS,          0,   "<global probe args>",     1, _ARG_1(_ARG(        env, DummyGlobal)))
+PROBE_POINT(JS_RUNTIME_CREATE,          1,   "JSRuntime_Create",        1, _ARG_1(_ARG(    runtime, JSRuntimePtr)))
+PROBE_POINT(JS_RUNTIME_DESTROY,         2,   "JSRuntime_Destroy",       1, _ARG_1(_ARG(    runtime, JSRuntimePtr)))
+PROBE_POINT(JS_SHUTDOWN,                3,   "JS_Shutdown",             0, _NO_ARGS)
+PROBE_POINT(JS_FUNCTION_ENTER,          4,   "JS_EnterFunction",        4, _ARG_4(_ARG(    context, JSContextPtr),
+                                                                                  _ARG(   function, JSFunctionPtr),
+                                                                                  _ARG(     script, JSScriptPtr),
+                                                                                  _ARG(    counter, int)))
+PROBE_POINT(JS_FUNCTION_EXIT,           5,   "JS_ExitFunction",         4, _ARG_4(_ARG(    context, JSContextPtr),
+                                                                                  _ARG(   function, JSFunctionPtr),
+                                                                                  _ARG(     script, JSScriptPtr),
+                                                                                  _ARG(    counter, int)))
+PROBE_POINT(JS_WILL_EXECUTE_SCRIPT,     6,   "JS_WillExecuteScript",    2, _ARG_2(_ARG(    context, JSContextPtr),
+                                                                                  _ARG(     script, JSScriptPtr)))
+PROBE_POINT(JS_DID_EXECUTE_SCRIPT,      7,   "JS_DidExecuteScript",     2, _ARG_2(_ARG(    context, JSContextPtr),
+                                                                                  _ARG(     script, JSScriptPtr)))
+PROBE_POINT(JS_WILL_RESIZE_HEAP,        8,   "JS_WillResizeHeap",       3, _ARG_3(_ARG(compartment, JSCompartmentPtr),
+                                                                                  _ARG(    oldSize, size_t),
+                                                                                  _ARG(    newSize, size_t)))
+PROBE_POINT(JS_OBJECT_CREATE,           9,   "JS_CreateObject",         2, _ARG_2(_ARG(    context, JSContextPtr),
+                                                                                  _ARG(     object, JSObjectPtr)))
+PROBE_POINT(JS_OBJECT_RESIZE,          10,   "JS_ResizeObject",         4, _ARG_4(_ARG(    context, JSContextPtr),
+                                                                                  _ARG(     object, JSObjectPtr),
+                                                                                  _ARG(    oldSize, size_t),
+                                                                                  _ARG(    newSize, size_t)))
+PROBE_POINT(JS_OBJECT_FINALIZE,        11,   "JS_FinalizeObject",       1, _ARG_1(_ARG(     object, JSObjectPtr)))
+PROBE_POINT(JS_STRING_CREATE,          12,   "JS_CreateString",         3, _ARG_3(_ARG(    context, JSContextPtr),
+                                                                                  _ARG(     string, JSStringPtr),
+                                                                                  _ARG(     length, size_t)))
+PROBE_POINT(JS_STRING_FINALIZE,        13,   "JS_FinalizeString",       1, _ARG_1(_ARG(     string, JSStringPtr)))
+PROBE_POINT(JS_WILL_COMPILE_SCRIPT,    14,   "JS_WillCompileScript",    3, _ARG_3(_ARG(    context, JSContextPtr),
+                                                                                  _ARG(   filename, ConstCharPtr),
+                                                                                  _ARG(     lineno, int)))
+PROBE_POINT(JS_DID_COMPILE_SCRIPT,     15,   "JS_DidCompileScript",     4, _ARG_4(_ARG(    context, JSContextPtr),
+                                                                                  _ARG(     script, JSScriptPtr),
+                                                                                  _ARG(   filename, ConstCharPtr),
+                                                                                  _ARG(     lineno, int)))
+PROBE_POINT(JS_WILL_CALL_NATIVE,       16,   "JS_WillCallNative",       2, _ARG_2(_ARG(    context, JSContextPtr),
+                                                                                  _ARG(   function, JSFunctionPtr)))
+PROBE_POINT(JS_DID_CALL_NATIVE,        17,   "JS_DidCallNative",        2, _ARG_2(_ARG(    context, JSContextPtr),
+                                                                                  _ARG(   function, JSFunctionPtr)))
+PROBE_POINT(JS_ACQUIRE_MEMORY,         18,   "JS_AcquireMemory",        3, _ARG_3(_ARG(    context, JSContextPtr),
+                                                                                  _ARG(    address, VoidPtr),
+                                                                                  _ARG(     nbytes, size_t)))
+PROBE_POINT(JS_RELEASE_MEMORY,         19,   "JS_ReleaseMemory",        3, _ARG_3(_ARG(    context, JSContextPtr),
+                                                                                  _ARG(    address, VoidPtr),
+                                                                                  _ARG(     nbytes, size_t)))
+PROBE_POINT(COMPARTMENT_GC_DID_START,  20,   "GC_DidStartCompartment",  2, _ARG_2(_ARG(    runtime, JSRuntimePtr),
+                                                                                  _ARG(compartment, JSCompartmentPtr)))
+PROBE_POINT(COMPARTMENT_GC_WILL_END,   21,   "GC_DidEndCompartment",    2, _ARG_2(_ARG(    runtime, JSRuntimePtr),
+                                                                                  _ARG(compartment, JSCompartmentPtr)))
+PROBE_POINT(GLOBAL_GC_DID_START,       22,   "GC_DidStartGlobal",       1, _ARG_1(_ARG(    runtime, JSRuntimePtr)))
+PROBE_POINT(GLOBAL_GC_WILL_END,        23,   "GC_DidEndGlobal",         1, _ARG_1(_ARG(    runtime, JSRuntimePtr)))
+PROBE_POINT(GC_MARK_PHASE_START,       24,   "GC_MarkPhaseStart",       0, _NO_ARGS)
+PROBE_POINT(GC_MARK_PHASE_END,         25,   "GC_MarkPhaseEnd",         0, _NO_ARGS)
+PROBE_POINT(GC_SWEEP_PHASE_START,      26,   "GC_SweepPhaseStart",      0, _NO_ARGS)
+PROBE_POINT(GC_SWEEP_PHASE_END,        27,   "GC_SweepPhaseEnd",        0, _NO_ARGS)
+
+
+
+/* This table defines transformation functions that operate on
+ * ProbeValues.  in_type and out_type are used for argument checking
+ * at runtime, and refer to the the ProbeType's `tyname`
+ * field. apiname refers to the property name to which this transform
+ * will be bound in JavaScript. The concatenation of in_type and
+ * apiname should be unique.
+ * 
+ *  Includers must define a PROBE_TRANS macro of the following form:
+ * 
+ * #define PROBE_TRANS(transformFn, apiname, id, in_type,out_type) ...
+ */
+
+/* legend:  tranformFn,                    apiname,           id,  in_type,             out_type */
+PROBE_TRANS(runtime_gcBytes,               gcBytes,            1,  JSRuntimePtr,        size_t)
+PROBE_TRANS(runtime_gcMaxBytes,            gcMaxBytes,         2,  JSRuntimePtr,        size_t)
+PROBE_TRANS(runtime_gcMaxMallocBytes,      gcMaxMallocBytes,   3,  JSRuntimePtr,        size_t)
+PROBE_TRANS(compartment_runtime,           runtime,            4,  JSCompartmentPtr,    JSRuntimePtr)
+PROBE_TRANS(compartment_gcBytes,           gcBytes,            5,  JSCompartmentPtr,    size_t)
+PROBE_TRANS(compartment_gcTriggerBytes,    gcTriggerBytes,     6,  JSCompartmentPtr,    size_t)
+PROBE_TRANS(compartment_id,                id,                 7,  JSCompartmentPtr,    intptr_t)
+PROBE_TRANS(env_currentTimeMS,             currentTimeMS,      8,  DummyGlobal,         double)
+
+/* teardown PROBE_POINT helpers */
+#undef _NO_ARGS
+#undef _ARG
+#undef _ARG_1
+#undef _ARG_2
+#undef _ARG_3
+#undef _ARG_4
+
+/* teardown any dummy-defaulted x-macros */
+
+#ifdef _PROBE_POINT_DEFAULTED
+#undef PROBE_POINT
+#undef _PROBE_POINT_DEFAULTED
+#endif
+
+#ifdef _PROBE_TYPE_DEFAULTED
+#undef PROBE_TYPE
+#undef _PROBE_TYPE_DEFAULTED
+#endif
+
+#ifdef _PROBE_TRANS_DEFAULTED
+#undef PROBE_TRANS
+#undef _PROBE_TRANS_DEFAULTED
+#endif