Skip to content

Commit 7a1c10b

Browse files
committed
gc.c: expand sorted pages
* gc.c (heap_page_allocate): expand sorted pages before inserting allocated new page. [Bug ruby#12670] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59136 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent ea57d84 commit 7a1c10b

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

KNOWNBUGS.rb

-10
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,3 @@
55
# This test file includes tests which point out known bugs.
66
# So all tests will cause failure.
77
#
8-
9-
assert_normal_exit("#{<<-";END;"}", timeout: 5)
10-
begin
11-
require "-test-/typeddata"
12-
rescue LoadError
13-
else
14-
n = 1 << 20
15-
Bug::TypedData.make(n)
16-
end
17-
;END;

gc.c

+31-19
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,29 @@ rb_objspace_free(rb_objspace_t *objspace)
13701370
free(objspace);
13711371
}
13721372

1373+
static void
1374+
heap_pages_expand_sorted_to(rb_objspace_t *objspace, size_t next_length)
1375+
{
1376+
struct heap_page **sorted;
1377+
size_t size = next_length * sizeof(struct heap_page *);
1378+
1379+
gc_report(3, objspace, "heap_pages_expand_sorted: next_length: %d, size: %d\n", (int)next_length, (int)size);
1380+
1381+
if (heap_pages_sorted_length > 0) {
1382+
sorted = (struct heap_page **)realloc(heap_pages_sorted, size);
1383+
if (sorted) heap_pages_sorted = sorted;
1384+
}
1385+
else {
1386+
sorted = heap_pages_sorted = (struct heap_page **)malloc(size);
1387+
}
1388+
1389+
if (sorted == 0) {
1390+
rb_memerror();
1391+
}
1392+
1393+
heap_pages_sorted_length = next_length;
1394+
}
1395+
13731396
static void
13741397
heap_pages_expand_sorted(rb_objspace_t *objspace)
13751398
{
@@ -1378,24 +1401,7 @@ heap_pages_expand_sorted(rb_objspace_t *objspace)
13781401
next_length += heap_tomb->total_pages;
13791402

13801403
if (next_length > heap_pages_sorted_length) {
1381-
struct heap_page **sorted;
1382-
size_t size = next_length * sizeof(struct heap_page *);
1383-
1384-
gc_report(3, objspace, "heap_pages_expand_sorted: next_length: %d, size: %d\n", (int)next_length, (int)size);
1385-
1386-
if (heap_pages_sorted_length > 0) {
1387-
sorted = (struct heap_page **)realloc(heap_pages_sorted, size);
1388-
if (sorted) heap_pages_sorted = sorted;
1389-
}
1390-
else {
1391-
sorted = heap_pages_sorted = (struct heap_page **)malloc(size);
1392-
}
1393-
1394-
if (sorted == 0) {
1395-
rb_memerror();
1396-
}
1397-
1398-
heap_pages_sorted_length = next_length;
1404+
heap_pages_expand_sorted_to(objspace, next_length);
13991405
}
14001406
}
14011407

@@ -1533,6 +1539,9 @@ heap_page_allocate(rb_objspace_t *objspace)
15331539
rb_bug("same heap page is allocated: %p at %"PRIuVALUE, (void *)page_body, (VALUE)mid);
15341540
}
15351541
}
1542+
if (heap_allocated_pages >= heap_pages_sorted_length) {
1543+
heap_pages_expand_sorted_to(objspace, heap_allocated_pages + 1);
1544+
}
15361545
if (hi < heap_allocated_pages) {
15371546
MEMMOVE(&heap_pages_sorted[hi+1], &heap_pages_sorted[hi], struct heap_page_header*, heap_allocated_pages - hi);
15381547
}
@@ -1542,7 +1551,10 @@ heap_page_allocate(rb_objspace_t *objspace)
15421551
heap_allocated_pages++;
15431552
objspace->profile.total_allocated_pages++;
15441553

1545-
if (RGENGC_CHECK_MODE) assert(heap_allocated_pages <= heap_pages_sorted_length);
1554+
if (heap_allocated_pages > heap_pages_sorted_length) {
1555+
rb_bug("heap_page_allocate: allocated(%"PRIdSIZE") > sorted(%"PRIdSIZE")",
1556+
heap_allocated_pages, heap_pages_sorted_length);
1557+
}
15461558

15471559
if (heap_pages_lomem == 0 || heap_pages_lomem > start) heap_pages_lomem = start;
15481560
if (heap_pages_himem < end) heap_pages_himem = end;

test/-ext-/typeddata/test_typeddata.rb

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ def test_wrong_argtype
1919
end
2020

2121
def test_deferred_free
22-
skip 'not solved'
23-
2422
assert_ruby_status([], "#{<<-"begin;"}\n#{<<-"end;"}")
2523
require "-test-/typeddata"
2624
begin;

0 commit comments

Comments
 (0)