public
Created

  • Download Gist
gc_bench.rb
Ruby
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
GC.enable_stats
 
class S
def initialize(a)
@a = a
end
end
 
ITER = 5
Benchmark.bmbm do |results|
results.report("GC") do
ITER.times do
1.upto(10000) {
tmp = [0,1,2,3,4,5,6,7,8,9]
}
tmp = nil
l=nil
100000.times {
l = S.new(l)
}
GC.start
l = []
100000.times {
l.push([l])
}
GC.start
100000.times {
Time.now
}
100000.times {|i|
i.to_s
}
end
end
end
 
puts "\n\nGC allocations #{GC.num_allocations}, GC collections #{GC.collections}, GC time #{GC.time}"
gcc_version.txt
1 2 3 4 5 6
methodmissing:rubyenterpriseedition187-248 lourens$ gcc -v
Using built-in specs.
Target: x86_64-apple-darwin10
Configured with: ../gcc-4.4.1/configure --prefix=/opt/local --build=x86_64-apple-darwin10 --enable-languages=c,c++,objc,obj-c++,java,fortran --libdir=/opt/local/lib/gcc44 --includedir=/opt/local/include/gcc44 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.4 --with-gxx-include-dir=/opt/local/include/gcc44/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local
Thread model: posix
gcc version 4.4.1 (GCC)
threaded_code_gc.diff
Diff
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
diff --git a/configure.in b/configure.in
index 090077e..59cb074 100644
--- a/configure.in
+++ b/configure.in
@@ -670,6 +670,15 @@ if test "$use_setreuid" = yes; then
AC_DEFINE(USE_SETREUID)
AC_DEFINE(USE_SETREGID)
fi
+
+AC_ARG_ENABLE(threaded-dispatch,
+ [ --enable-threaded-dispatch use threaded dispatch for rb_eval],
+ [use_threaded_dispatch=$enableval])
+if test "$use_threaded_dispatch" = yes; then
+ AC_DEFINE(USE_THREADED_DISPATCH)
+ XCFLAGS="$XCFLAGS -fno-gcse"
+fi
+
AC_STRUCT_TIMEZONE
AC_CACHE_CHECK(for struct tm.tm_gmtoff, rb_cv_member_struct_tm_tm_gmtoff,
[AC_TRY_COMPILE([#include <time.h>],
diff --git a/gc.c b/gc.c
index 8c1c6d6..dda1835 100644
--- a/gc.c
+++ b/gc.c
@@ -1395,12 +1395,219 @@ rb_gc_mark(ptr)
}
}
+#ifdef THREADED_DISPATCH
+#define NODE_MARK_TABLE \
+static const int node_mark_table[104] = { \
+ &&NODE_MARK_NODE_UNDEF - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_OP_ASGN1 - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_CDECL - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_OP_ASGN1 - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_CLASS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_CLASS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_UNDEF - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_CLASS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_CLASS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_SVALUE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_SVALUE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NONE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_CLASS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_CLASS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_OP_ASGN1 - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_UNDEF - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_CLASS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_UNDEF - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_UNDEF - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_UNDEF - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_UNDEF - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_UNDEF - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_CDECL - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_UNDEF - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_UNDEF - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_OP_ASGN1 - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NONE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_OP_ASGN1 - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NEWLINE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NEWLINE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_OP_ASGN1 - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_SVALUE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_SVALUE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_SVALUE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NONE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_SVALUE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_SVALUE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_SVALUE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_OP_ASGN1 - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_SVALUE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_OP_ASGN1 - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_UNDEF - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_OP_ASGN1 - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_OP_ASGN1 - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NONE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NONE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_SVALUE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_SVALUE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_SVALUE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_CDECL - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NEWLINE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_OP_ASGN1 - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_UNDEF - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_CLASS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_SVALUE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_UNDEF - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_CLASS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ARGS - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_SVALUE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NEWLINE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_POSTEXE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_ALLOCA - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NONE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NONE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NONE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NONE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NONE - &&NODE_MARK_NODE_UNDEF, \
+ &&NODE_MARK_NODE_NONE - &&NODE_MARK_NODE_UNDEF \
+};
+#define OBJ_MARK_TABLE \
+static const int obj_mark_table[64] = { \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_OBJECT - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_MODULE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_MODULE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_MODULE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_BLKTAG - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_STRING - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_BLKTAG - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_ARRAY - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_HASH - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_STRUCT - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_BLKTAG - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_BLKTAG - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_DATA - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_MATCH - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_BLKTAG - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_VARMAP - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_T_SCOPE - &&OBJ_MARK_NONE, \
+ &&OBJ_MARK_NONE - &&OBJ_MARK_NONE, \
+};
+#define MARK_NODE(nd) NODE_MARK_##nd:
+#define MARK_NODE_ALIAS(nd)
+#define MARK_NODE_BEGIN goto *(&&NODE_MARK_NODE_UNDEF + node_mark_table[nd_type(obj)]);
+#define MARK_NODE_DEFAULT NODE_MARK_NODE_NONE:
+#define MARK_NODE_END
+#define MARK_NEXT goto again;
+#define MARK_OBJ_BEGIN goto *(&&OBJ_MARK_NONE + obj_mark_table[obj->as.basic.flags & T_MASK]);
+#define MARK_OBJ(obj) OBJ_MARK_##obj:
+#define MARK_OBJ_ALIAS(obj)
+#define BREAK return;
+#define MARK_OBJ_DEFAULT OBJ_MARK_NONE:
+#define MARK_OBJ_END
+#else
+#define NODE_MARK_TABLE
+#define MARK_NODE_BEGIN switch (nd_type(obj)) {
+#define MARK_NODE(nd) case (nd):
+#define MARK_NODE_ALIAS(nd) case (nd):
+#define MARK_NODE_DEFAULT default:
+#define MARK_NODE_END }
+#define OBJ_MARK_TABLE
+#define MARK_NEXT goto again;
+#define MARK_OBJ_BEGIN switch (obj->as.basic.flags & T_MASK) {
+#define MARK_OBJ(obj) case (obj):
+#define MARK_OBJ_ALIAS(obj) case (obj):
+#define BREAK break;
+#define MARK_OBJ_DEFAULT default:
+#define MARK_OBJ_END }
+#endif
+
static void
gc_mark_children(ptr)
VALUE ptr;
{
RVALUE *obj = RANY(ptr);
+ NODE_MARK_TABLE;
+ OBJ_MARK_TABLE;
+
goto marking; /* skip */
again:
@@ -1423,126 +1630,126 @@ gc_mark_children(ptr)
case T_NODE:
mark_source_filename(obj->as.node.nd_file);
- switch (nd_type(obj)) {
- case NODE_IF: /* 1,2,3 */
- case NODE_FOR:
- case NODE_ITER:
- case NODE_CREF:
- case NODE_WHEN:
- case NODE_MASGN:
- case NODE_RESCUE:
- case NODE_RESBODY:
- case NODE_CLASS:
+ MARK_NODE_BEGIN;
+ MARK_NODE_ALIAS(NODE_IF); /* 1,2,3 */
+ MARK_NODE_ALIAS(NODE_FOR);
+ MARK_NODE_ALIAS(NODE_ITER);
+ MARK_NODE_ALIAS(NODE_CREF);
+ MARK_NODE_ALIAS(NODE_WHEN);
+ MARK_NODE_ALIAS(NODE_MASGN);
+ MARK_NODE_ALIAS(NODE_RESCUE);
+ MARK_NODE_ALIAS(NODE_RESBODY);
+ MARK_NODE(NODE_CLASS);
gc_mark((VALUE)obj->as.node.u2.node);
/* fall through */
- case NODE_BLOCK: /* 1,3 */
- case NODE_ARRAY:
- case NODE_DSTR:
- case NODE_DXSTR:
- case NODE_DREGX:
- case NODE_DREGX_ONCE:
- case NODE_FBODY:
- case NODE_ENSURE:
- case NODE_CALL:
- case NODE_DEFS:
- case NODE_OP_ASGN1:
+ MARK_NODE_ALIAS(NODE_BLOCK); /* 1,3 */
+ MARK_NODE_ALIAS(NODE_ARRAY);
+ MARK_NODE_ALIAS(NODE_DSTR);
+ MARK_NODE_ALIAS(NODE_DXSTR);
+ MARK_NODE_ALIAS(NODE_DREGX);
+ MARK_NODE_ALIAS(NODE_DREGX_ONCE);
+ MARK_NODE_ALIAS(NODE_FBODY);
+ MARK_NODE_ALIAS(NODE_ENSURE);
+ MARK_NODE_ALIAS(NODE_CALL);
+ MARK_NODE_ALIAS(NODE_DEFS);
+ MARK_NODE(NODE_OP_ASGN1);
gc_mark((VALUE)obj->as.node.u1.node);
/* fall through */
- case NODE_SUPER: /* 3 */
- case NODE_FCALL:
- case NODE_DEFN:
- case NODE_NEWLINE:
+ MARK_NODE_ALIAS(NODE_SUPER); /* 3 */
+ MARK_NODE_ALIAS(NODE_FCALL);
+ MARK_NODE_ALIAS(NODE_DEFN);
+ MARK_NODE(NODE_NEWLINE);
ptr = (VALUE)obj->as.node.u3.node;
- goto again;
-
- case NODE_WHILE: /* 1,2 */
- case NODE_UNTIL:
- case NODE_AND:
- case NODE_OR:
- case NODE_CASE:
- case NODE_SCLASS:
- case NODE_DOT2:
- case NODE_DOT3:
- case NODE_FLIP2:
- case NODE_FLIP3:
- case NODE_MATCH2:
- case NODE_MATCH3:
- case NODE_OP_ASGN_OR:
- case NODE_OP_ASGN_AND:
- case NODE_MODULE:
- case NODE_ALIAS:
- case NODE_VALIAS:
- case NODE_ARGS:
+ MARK_NEXT;
+
+ MARK_NODE_ALIAS(NODE_WHILE); /* 1,2 */
+ MARK_NODE_ALIAS(NODE_UNTIL);
+ MARK_NODE_ALIAS(NODE_AND);
+ MARK_NODE_ALIAS(NODE_OR);
+ MARK_NODE_ALIAS(NODE_CASE);
+ MARK_NODE_ALIAS(NODE_SCLASS);
+ MARK_NODE_ALIAS(NODE_DOT2);
+ MARK_NODE_ALIAS(NODE_DOT3);
+ MARK_NODE_ALIAS(NODE_FLIP2);
+ MARK_NODE_ALIAS(NODE_FLIP3);
+ MARK_NODE_ALIAS(NODE_MATCH2);
+ MARK_NODE_ALIAS(NODE_MATCH3);
+ MARK_NODE_ALIAS(NODE_OP_ASGN_OR);
+ MARK_NODE_ALIAS(NODE_OP_ASGN_AND);
+ MARK_NODE_ALIAS(NODE_MODULE);
+ MARK_NODE_ALIAS(NODE_ALIAS);
+ MARK_NODE_ALIAS(NODE_VALIAS);
+ MARK_NODE(NODE_ARGS);
gc_mark((VALUE)obj->as.node.u1.node);
/* fall through */
- case NODE_METHOD: /* 2 */
- case NODE_NOT:
- case NODE_GASGN:
- case NODE_LASGN:
- case NODE_DASGN:
- case NODE_DASGN_CURR:
- case NODE_IASGN:
- case NODE_CVDECL:
- case NODE_CVASGN:
- case NODE_COLON3:
- case NODE_OPT_N:
- case NODE_EVSTR:
- case NODE_UNDEF:
+ MARK_NODE_ALIAS(NODE_METHOD); /* 2 */
+ MARK_NODE_ALIAS(NODE_NOT);
+ MARK_NODE_ALIAS(NODE_GASGN);
+ MARK_NODE_ALIAS(NODE_LASGN);
+ MARK_NODE_ALIAS(NODE_DASGN);
+ MARK_NODE_ALIAS(NODE_DASGN_CURR);
+ MARK_NODE_ALIAS(NODE_IASGN);
+ MARK_NODE_ALIAS(NODE_CVDECL);
+ MARK_NODE_ALIAS(NODE_CVASGN);
+ MARK_NODE_ALIAS(NODE_COLON3);
+ MARK_NODE_ALIAS(NODE_OPT_N);
+ MARK_NODE_ALIAS(NODE_EVSTR);
+ MARK_NODE(NODE_UNDEF);
ptr = (VALUE)obj->as.node.u2.node;
- goto again;
-
- case NODE_HASH: /* 1 */
- case NODE_LIT:
- case NODE_STR:
- case NODE_XSTR:
- case NODE_DEFINED:
- case NODE_MATCH:
- case NODE_RETURN:
- case NODE_BREAK:
- case NODE_NEXT:
- case NODE_YIELD:
- case NODE_COLON2:
- case NODE_SPLAT:
- case NODE_TO_ARY:
- case NODE_SVALUE:
+ MARK_NEXT;
+
+ MARK_NODE_ALIAS(NODE_HASH); /* 1 */
+ MARK_NODE_ALIAS(NODE_LIT);
+ MARK_NODE_ALIAS(NODE_STR);
+ MARK_NODE_ALIAS(NODE_XSTR);
+ MARK_NODE_ALIAS(NODE_DEFINED);
+ MARK_NODE_ALIAS(NODE_MATCH);
+ MARK_NODE_ALIAS(NODE_RETURN);
+ MARK_NODE_ALIAS(NODE_BREAK);
+ MARK_NODE_ALIAS(NODE_NEXT);
+ MARK_NODE_ALIAS(NODE_YIELD);
+ MARK_NODE_ALIAS(NODE_COLON2);
+ MARK_NODE_ALIAS(NODE_SPLAT);
+ MARK_NODE_ALIAS(NODE_TO_ARY);
+ MARK_NODE(NODE_SVALUE);
ptr = (VALUE)obj->as.node.u1.node;
- goto again;
+ MARK_NEXT;
- case NODE_SCOPE: /* 2,3 */
- case NODE_BLOCK_PASS:
- case NODE_CDECL:
+ MARK_NODE_ALIAS(NODE_SCOPE); /* 2,3 */
+ MARK_NODE_ALIAS(NODE_BLOCK_PASS);
+ MARK_NODE(NODE_CDECL);
gc_mark((VALUE)obj->as.node.u3.node);
ptr = (VALUE)obj->as.node.u2.node;
- goto again;
-
- case NODE_ZARRAY: /* - */
- case NODE_ZSUPER:
- case NODE_CFUNC:
- case NODE_VCALL:
- case NODE_GVAR:
- case NODE_LVAR:
- case NODE_DVAR:
- case NODE_IVAR:
- case NODE_CVAR:
- case NODE_NTH_REF:
- case NODE_BACK_REF:
- case NODE_REDO:
- case NODE_RETRY:
- case NODE_SELF:
- case NODE_NIL:
- case NODE_TRUE:
- case NODE_FALSE:
- case NODE_ATTRSET:
- case NODE_BLOCK_ARG:
- case NODE_POSTEXE:
- break;
- case NODE_ALLOCA:
+ MARK_NEXT;
+
+ MARK_NODE_ALIAS(NODE_ZARRAY); /* - */
+ MARK_NODE_ALIAS(NODE_ZSUPER);
+ MARK_NODE_ALIAS(NODE_CFUNC);
+ MARK_NODE_ALIAS(NODE_VCALL);
+ MARK_NODE_ALIAS(NODE_GVAR);
+ MARK_NODE_ALIAS(NODE_LVAR);
+ MARK_NODE_ALIAS(NODE_DVAR);
+ MARK_NODE_ALIAS(NODE_IVAR);
+ MARK_NODE_ALIAS(NODE_CVAR);
+ MARK_NODE_ALIAS(NODE_NTH_REF);
+ MARK_NODE_ALIAS(NODE_BACK_REF);
+ MARK_NODE_ALIAS(NODE_REDO);
+ MARK_NODE_ALIAS(NODE_RETRY);
+ MARK_NODE_ALIAS(NODE_SELF);
+ MARK_NODE_ALIAS(NODE_NIL);
+ MARK_NODE_ALIAS(NODE_TRUE);
+ MARK_NODE_ALIAS(NODE_FALSE);
+ MARK_NODE_ALIAS(NODE_ATTRSET);
+ MARK_NODE_ALIAS(NODE_BLOCK_ARG);
+ MARK_NODE(NODE_POSTEXE);
+ BREAK;
+ MARK_NODE(NODE_ALLOCA);
mark_locations_array((VALUE*)obj->as.node.u1.value,
obj->as.node.u3.cnt);
ptr = (VALUE)obj->as.node.u2.node;
- goto again;
+ MARK_NEXT;
- default: /* unlisted NODE */
+ MARK_NODE_DEFAULT; /* unlisted NODE */
if (is_pointer_to_heap(obj->as.node.u1.node)) {
gc_mark((VALUE)obj->as.node.u1.node);
}
@@ -1551,26 +1758,26 @@ gc_mark_children(ptr)
}
if (is_pointer_to_heap(obj->as.node.u3.node)) {
ptr = (VALUE)obj->as.node.u3.node;
- goto again;
+ MARK_NEXT;
}
- }
+ MARK_NODE_END;
return; /* no need to mark class. */
}
gc_mark(obj->as.basic.klass);
- switch (obj->as.basic.flags & T_MASK) {
- case T_ICLASS:
- case T_CLASS:
- case T_MODULE:
+ MARK_OBJ_BEGIN;
+ MARK_OBJ_ALIAS(T_ICLASS);
+ MARK_OBJ_ALIAS(T_CLASS);
+ MARK_OBJ(T_MODULE);
mark_tbl(obj->as.klass.m_tbl);
mark_tbl(obj->as.klass.iv_tbl);
ptr = obj->as.klass.super;
- goto again;
+ MARK_NEXT;
- case T_ARRAY:
+ MARK_OBJ(T_ARRAY);
if (FL_TEST(obj, ELTS_SHARED)) {
ptr = obj->as.array.aux.shared;
- goto again;
+ MARK_NEXT;
}
else {
VALUE *ptr = obj->as.array.ptr;
@@ -1579,49 +1786,49 @@ gc_mark_children(ptr)
gc_mark(*ptr++);
}
}
- break;
+ BREAK;
- case T_HASH:
+ MARK_OBJ(T_HASH);
mark_hash(obj->as.hash.tbl);
ptr = obj->as.hash.ifnone;
- goto again;
+ MARK_NEXT;
- case T_STRING:
+ MARK_OBJ(T_STRING);
#define STR_ASSOC FL_USER3 /* copied from string.c */
if (FL_TEST(obj, ELTS_SHARED|STR_ASSOC)) {
ptr = obj->as.string.aux.shared;
- goto again;
+ MARK_NEXT;
}
- break;
+ BREAK;
- case T_DATA:
+ MARK_OBJ(T_DATA);
if (obj->as.data.dmark) (*obj->as.data.dmark)(DATA_PTR(obj));
- break;
+ BREAK;
- case T_OBJECT:
+ MARK_OBJ(T_OBJECT);
mark_tbl(obj->as.object.iv_tbl);
- break;
+ BREAK;
- case T_FILE:
- case T_REGEXP:
- case T_FLOAT:
- case T_BIGNUM:
- case T_BLKTAG:
- break;
+ MARK_OBJ_ALIAS(T_FILE);
+ MARK_OBJ_ALIAS(T_REGEXP);
+ MARK_OBJ_ALIAS(T_FLOAT);
+ MARK_OBJ_ALIAS(T_BIGNUM);
+ MARK_OBJ(T_BLKTAG);
+ BREAK;
- case T_MATCH:
+ MARK_OBJ(T_MATCH);
if (obj->as.match.str) {
ptr = obj->as.match.str;
- goto again;
+ MARK_NEXT;
}
- break;
+ BREAK;
- case T_VARMAP:
+ MARK_OBJ(T_VARMAP);
gc_mark(obj->as.varmap.val);
ptr = (VALUE)obj->as.varmap.next;
- goto again;
+ MARK_NEXT;
- case T_SCOPE:
+ MARK_OBJ(T_SCOPE);
if (obj->as.scope.local_vars && (obj->as.scope.flags & SCOPE_MALLOC)) {
int n = obj->as.scope.local_tbl[0]+1;
VALUE *vars = &obj->as.scope.local_vars[-1];
@@ -1630,22 +1837,22 @@ gc_mark_children(ptr)
gc_mark(*vars++);
}
}
- break;
+ BREAK;
- case T_STRUCT:
+ MARK_OBJ(T_STRUCT);
{
VALUE *ptr = obj->as.rstruct.ptr;
VALUE *pend = ptr + obj->as.rstruct.len;
while (ptr < pend)
gc_mark(*ptr++);
}
- break;
+ BREAK;
- default:
+ MARK_OBJ_DEFAULT;
rb_bug("rb_gc_mark(): unknown data type 0x%lx(0x%lx) %s",
obj->as.basic.flags & T_MASK, obj,
is_pointer_to_heap(obj) ? "corrupted object" : "non object");
- }
+ MARK_OBJ_END;
}
static int obj_free _((VALUE));
diff --git a/ruby.h b/ruby.h
index 4d003a8..8cc114e 100644
--- a/ruby.h
+++ b/ruby.h
@@ -53,6 +53,10 @@ extern "C" {
#include <stddef.h>
#include <stdio.h>
+#if (defined(__GNUC__) || defined (__SUNPRO_C)) && defined(USE_THREADED_DISPATCH)
+#define THREADED_DISPATCH
+#endif
+
/* need to include <ctype.h> to use these macros */
#ifndef ISPRINT
#define ISASCII(c) isascii((int)(unsigned char)(c))
with_computed_goto.txt
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
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.920000 0.110000 2.030000 ( 2.037465)
----------------------------- total: 2.030000sec
 
user system total real
GC 1.890000 0.090000 1.980000 ( 1.986451)
 
 
GC allocations 6100164, GC collections 76, GC time 1285786
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.920000 0.100000 2.020000 ( 2.034541)
----------------------------- total: 2.020000sec
 
user system total real
GC 1.890000 0.100000 1.990000 ( 1.983895)
 
 
GC allocations 6100164, GC collections 76, GC time 1285663
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.940000 0.110000 2.050000 ( 2.083771)
----------------------------- total: 2.050000sec
 
user system total real
GC 1.880000 0.100000 1.980000 ( 1.983069)
 
 
GC allocations 6100164, GC collections 76, GC time 1298704
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.930000 0.110000 2.040000 ( 2.046354)
----------------------------- total: 2.040000sec
 
user system total real
GC 1.880000 0.090000 1.970000 ( 1.984479)
 
 
GC allocations 6100164, GC collections 76, GC time 1291290
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.920000 0.100000 2.020000 ( 2.034159)
----------------------------- total: 2.020000sec
 
user system total real
GC 1.890000 0.100000 1.990000 ( 1.986119)
 
 
GC allocations 6100164, GC collections 76, GC time 1283219
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.930000 0.110000 2.040000 ( 2.042077)
----------------------------- total: 2.040000sec
 
user system total real
GC 1.890000 0.100000 1.990000 ( 2.000116)
 
 
GC allocations 6100164, GC collections 76, GC time 1295255
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.910000 0.100000 2.010000 ( 2.020122)
----------------------------- total: 2.010000sec
 
user system total real
GC 1.890000 0.100000 1.990000 ( 1.984007)
 
 
GC allocations 6100164, GC collections 76, GC time 1281519
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.930000 0.110000 2.040000 ( 2.046567)
----------------------------- total: 2.040000sec
 
user system total real
GC 1.880000 0.100000 1.980000 ( 1.983995)
 
 
GC allocations 6100164, GC collections 76, GC time 1293953
without_computed_goto.txt
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
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.890000 0.100000 1.990000 ( 2.002766)
----------------------------- total: 1.990000sec
 
user system total real
GC 1.880000 0.100000 1.980000 ( 1.978341)
 
 
GC allocations 6100164, GC collections 104, GC time 1350239
methodmissing:rubyenterpriseedition187-248 lourens$
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.880000 0.100000 1.980000 ( 1.994420)
----------------------------- total: 1.980000sec
 
user system total real
GC 1.870000 0.100000 1.970000 ( 1.975207)
 
 
GC allocations 6100164, GC collections 104, GC time 1347193
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.880000 0.100000 1.980000 ( 1.994267)
----------------------------- total: 1.980000sec
 
user system total real
GC 1.880000 0.100000 1.980000 ( 1.976741)
 
 
GC allocations 6100164, GC collections 104, GC time 1349683
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.900000 0.120000 2.020000 ( 2.034585)
----------------------------- total: 2.020000sec
 
user system total real
GC 1.880000 0.100000 1.980000 ( 2.012661)
 
 
GC allocations 6100164, GC collections 104, GC time 1374953
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.880000 0.100000 1.980000 ( 1.990765)
----------------------------- total: 1.980000sec
 
user system total real
GC 1.880000 0.110000 1.990000 ( 1.985680)
 
 
GC allocations 6100164, GC collections 104, GC time 1350603
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.890000 0.100000 1.990000 ( 1.994218)
----------------------------- total: 1.990000sec
 
user system total real
GC 1.870000 0.100000 1.970000 ( 1.975965)
 
 
GC allocations 6100164, GC collections 104, GC time 1348079
methodmissing:rubyenterpriseedition187-248 lourens$ ./ruby -Ilib gc_bench.rb
Rehearsal --------------------------------------
GC 1.890000 0.100000 1.990000 ( 1.997950)
----------------------------- total: 1.990000sec
 
user system total real
GC 1.870000 0.100000 1.970000 ( 1.975340)
 
 
GC allocations 6100164, GC collections 104, GC time 1349620

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.