| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 | 2 |
| 3 #include <stdlib.h> | 3 #include <stdlib.h> |
| 4 | 4 |
| 5 #include "v8.h" | 5 #include "v8.h" |
| 6 | 6 |
| 7 #include "execution.h" | 7 #include "execution.h" |
| 8 #include "factory.h" | 8 #include "factory.h" |
| 9 #include "macro-assembler.h" | 9 #include "macro-assembler.h" |
| 10 #include "global-handles.h" | 10 #include "global-handles.h" |
| (...skipping 1923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1934 // where there are 2 pages left instead of 1, then we should increase the | 1934 // where there are 2 pages left instead of 1, then we should increase the |
| 1935 // size of the first page a little in SizeOfFirstPage in spaces.cc. The | 1935 // size of the first page a little in SizeOfFirstPage in spaces.cc. The |
| 1936 // first page should be small in order to reduce memory used when the VM | 1936 // first page should be small in order to reduce memory used when the VM |
| 1937 // boots, but if the 20 small arrays don't fit on the first page then that's | 1937 // boots, but if the 20 small arrays don't fit on the first page then that's |
| 1938 // an indication that it is too small. | 1938 // an indication that it is too small. |
| 1939 HEAP->CollectAllAvailableGarbage("triggered really hard"); | 1939 HEAP->CollectAllAvailableGarbage("triggered really hard"); |
| 1940 CHECK_EQ(1, old_pointer_space->CountTotalPages()); | 1940 CHECK_EQ(1, old_pointer_space->CountTotalPages()); |
| 1941 } | 1941 } |
| 1942 | 1942 |
| 1943 | 1943 |
| 1944 // Tests the FlushEagerly class from heap.h |
| 1945 TEST(ReleaseUnoptimizedCode) { |
| 1946 i::FLAG_trace_gc = true; |
| 1947 // The optimizer can allocate stuff, messing up the test. |
| 1948 i::FLAG_crankshaft = false; |
| 1949 if (i::FLAG_always_opt) return; |
| 1950 InitializeVM(); |
| 1951 v8::HandleScope scope; |
| 1952 |
| 1953 PagedSpace* code_space = HEAP->code_space(); |
| 1954 CompileRun("var a = [];" |
| 1955 "var sum = 0;" |
| 1956 "for (var j = 0; j < 1e4; j++) {" |
| 1957 " var fn = new Function(" |
| 1958 " 'var k; var o = {}; for (k in o) { } return ' + j + ';');" |
| 1959 " sum += fn();" |
| 1960 "}"); |
| 1961 HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered for preparation"); |
| 1962 printf("%d\n", code_space->CountTotalPages()); |
| 1963 CHECK_GE(5, code_space->CountTotalPages()); |
| 1964 HEAP->CollectAllAvailableGarbage("triggered really hard"); |
| 1965 printf("%d\n", code_space->CountTotalPages()); |
| 1966 CHECK_LE(2, code_space->CountTotalPages()); |
| 1967 } |
| 1968 |
| 1969 |
| 1970 // Tests the FlushEagerly class from heap.h |
| 1971 TEST(ReleaseRegexpCode) { |
| 1972 i::FLAG_trace_gc = true; |
| 1973 // The optimizer can allocate stuff, messing up the test. |
| 1974 i::FLAG_crankshaft = false; |
| 1975 if (i::FLAG_always_opt) return; |
| 1976 InitializeVM(); |
| 1977 v8::HandleScope scope; |
| 1978 |
| 1979 PagedSpace* code_space = HEAP->code_space(); |
| 1980 CompileRun("var a = [];" |
| 1981 "for (var j = 0; j < 2e4; j++) {" |
| 1982 " var re = RegExp(j + '?');" |
| 1983 " a.push(re);" |
| 1984 " re.test('foo');" |
| 1985 "}"); |
| 1986 HEAP->CollectAllGarbage(Heap::kNoGCFlags, "triggered for preparation"); |
| 1987 printf("%d\n", code_space->CountTotalPages()); |
| 1988 CHECK_GT(15, code_space->CountTotalPages()); |
| 1989 HEAP->CollectAllAvailableGarbage("triggered really hard"); |
| 1990 printf("%d\n", code_space->CountTotalPages()); |
| 1991 CHECK_LE(2, code_space->CountTotalPages()); |
| 1992 } |
| 1993 |
| 1994 |
| 1944 TEST(Regress2237) { | 1995 TEST(Regress2237) { |
| 1945 InitializeVM(); | 1996 InitializeVM(); |
| 1946 v8::HandleScope scope; | 1997 v8::HandleScope scope; |
| 1947 Handle<String> slice(HEAP->empty_string()); | 1998 Handle<String> slice(HEAP->empty_string()); |
| 1948 | 1999 |
| 1949 { | 2000 { |
| 1950 // Generate a parent that lives in new-space. | 2001 // Generate a parent that lives in new-space. |
| 1951 v8::HandleScope inner_scope; | 2002 v8::HandleScope inner_scope; |
| 1952 const char* c = "This text is long enough to trigger sliced strings."; | 2003 const char* c = "This text is long enough to trigger sliced strings."; |
| 1953 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector(c)); | 2004 Handle<String> s = FACTORY->NewStringFromAscii(CStrVector(c)); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2237 // External source is being retained by the stack trace. | 2288 // External source is being retained by the stack trace. |
| 2238 CHECK(!resource->IsDisposed()); | 2289 CHECK(!resource->IsDisposed()); |
| 2239 | 2290 |
| 2240 CompileRun("error.stack; error.stack;"); | 2291 CompileRun("error.stack; error.stack;"); |
| 2241 HEAP->CollectAllAvailableGarbage(); | 2292 HEAP->CollectAllAvailableGarbage(); |
| 2242 // External source has been released. | 2293 // External source has been released. |
| 2243 CHECK(resource->IsDisposed()); | 2294 CHECK(resource->IsDisposed()); |
| 2244 | 2295 |
| 2245 delete resource; | 2296 delete resource; |
| 2246 } | 2297 } |
| OLD | NEW |