Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: test/cctest/test-api.cc

Issue 242074: Fix the stack limits setting API so it is usable. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/x64/simulator-x64.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
(...skipping 12 matching lines...) Expand all
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <stdlib.h> 28 #include <stdlib.h>
29 29
30 #include "v8.h" 30 #include "v8.h"
31 31
32 #include "api.h" 32 #include "api.h"
33 #include "compilation-cache.h" 33 #include "compilation-cache.h"
34 #include "execution.h"
34 #include "snapshot.h" 35 #include "snapshot.h"
35 #include "platform.h" 36 #include "platform.h"
36 #include "top.h" 37 #include "top.h"
37 #include "cctest.h" 38 #include "cctest.h"
38 39
39 static bool IsNaN(double x) { 40 static bool IsNaN(double x) {
40 #ifdef WIN32 41 #ifdef WIN32
41 return _isnan(x); 42 return _isnan(x);
42 #else 43 #else
43 return isnan(x); 44 return isnan(x);
(...skipping 7828 matching lines...) Expand 10 before | Expand all | Expand 10 after
7872 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); 7873 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL);
7873 } 7874 }
7874 7875
7875 7876
7876 // Test that idle notification can be handled when V8 has not yet been 7877 // Test that idle notification can be handled when V8 has not yet been
7877 // set up. 7878 // set up.
7878 THREADED_TEST(IdleNotification) { 7879 THREADED_TEST(IdleNotification) {
7879 for (int i = 0; i < 100; i++) v8::V8::IdleNotification(true); 7880 for (int i = 0; i < 100; i++) v8::V8::IdleNotification(true);
7880 for (int i = 0; i < 100; i++) v8::V8::IdleNotification(false); 7881 for (int i = 0; i < 100; i++) v8::V8::IdleNotification(false);
7881 } 7882 }
7883
7884
7885 static uint32_t* stack_limit;
7886
7887 static v8::Handle<Value> GetStackLimitCallback(const v8::Arguments& args) {
7888 stack_limit = reinterpret_cast<uint32_t*>(i::StackGuard::climit());
7889 return v8::Undefined();
7890 }
7891
7892
7893 // Uses the address of a local variable to determine the stack top now.
7894 // Given a size, returns an address that is that far from the current
7895 // top of stack.
7896 static uint32_t* ComputeStackLimit(uint32_t size) {
7897 uint32_t* answer = &size - (size / sizeof(size));
7898 // If the size is very large and the stack is very near the bottom of
7899 // memory then the calculation above may wrap around and give an address
7900 // that is above the (downwards-growing) stack. In that case we return
7901 // a very low address.
7902 if (answer > &size) return reinterpret_cast<uint32_t*>(sizeof(size));
7903 return answer;
7904 }
7905
7906
7907 TEST(SetResourceConstraints) {
7908 static const int K = 1024;
7909 uint32_t* set_limit = ComputeStackLimit(128 * K);
7910
7911 // Set stack limit.
7912 v8::ResourceConstraints constraints;
7913 constraints.set_stack_limit(set_limit);
7914 CHECK(v8::SetResourceConstraints(&constraints));
7915
7916 // Execute a script.
7917 v8::HandleScope scope;
7918 LocalContext env;
7919 Local<v8::FunctionTemplate> fun_templ =
7920 v8::FunctionTemplate::New(GetStackLimitCallback);
7921 Local<Function> fun = fun_templ->GetFunction();
7922 env->Global()->Set(v8_str("get_stack_limit"), fun);
7923 CompileRun("get_stack_limit();");
7924
7925 CHECK(stack_limit == set_limit);
7926 }
7927
7928
7929 TEST(SetResourceConstraintsInThread) {
7930 uint32_t* set_limit;
7931 {
7932 v8::Locker locker;
7933 static const int K = 1024;
7934 set_limit = ComputeStackLimit(128 * K);
7935
7936 // Set stack limit.
7937 v8::ResourceConstraints constraints;
7938 constraints.set_stack_limit(set_limit);
7939 CHECK(v8::SetResourceConstraints(&constraints));
7940
7941 // Execute a script.
7942 v8::HandleScope scope;
7943 LocalContext env;
7944 Local<v8::FunctionTemplate> fun_templ =
7945 v8::FunctionTemplate::New(GetStackLimitCallback);
7946 Local<Function> fun = fun_templ->GetFunction();
7947 env->Global()->Set(v8_str("get_stack_limit"), fun);
7948 CompileRun("get_stack_limit();");
7949
7950 CHECK(stack_limit == set_limit);
7951 }
7952 {
7953 v8::Locker locker;
7954 CHECK(stack_limit == set_limit);
7955 }
7956 }
OLDNEW
« no previous file with comments | « src/x64/simulator-x64.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698