< prev index next >

test/hotspot/gtest/code/test_dependencyContext.cpp

Print this page




  33   intptr_t _dependency_context;
  34 
  35   DependencyContext dependencies() {
  36     DependencyContext depContext(&_dependency_context);
  37     return depContext;
  38   }
  39 
  40   TestDependencyContext() : _dependency_context(DependencyContext::EMPTY) {
  41     CodeCache_lock->lock_without_safepoint_check();
  42 
  43     _nmethods[0] = reinterpret_cast<nmethod*>(0x8 * 0);
  44     _nmethods[1] = reinterpret_cast<nmethod*>(0x8 * 1);
  45     _nmethods[2] = reinterpret_cast<nmethod*>(0x8 * 2);
  46 
  47     dependencies().add_dependent_nmethod(_nmethods[2]);
  48     dependencies().add_dependent_nmethod(_nmethods[1]);
  49     dependencies().add_dependent_nmethod(_nmethods[0]);
  50   }
  51 
  52   ~TestDependencyContext() {
  53     dependencies().wipe();
  54     CodeCache_lock->unlock();
  55   }
  56 
  57   static bool has_stale_entries(DependencyContext ctx) {
  58     return ctx.has_stale_entries();
  59   }
  60 
  61 #ifndef PRODUCT
  62   static bool find_stale_entries(DependencyContext ctx) {
  63     return ctx.find_stale_entries();
  64   }
  65 #endif












  66 };
  67 
  68 static void test_remove_dependent_nmethod(int id, bool delete_immediately) {
  69   TestDependencyContext c;
  70   DependencyContext depContext = c.dependencies();
  71   NOT_PRODUCT(ASSERT_FALSE(TestDependencyContext::find_stale_entries(depContext)));
  72   ASSERT_FALSE(TestDependencyContext::has_stale_entries(depContext));
  73 
  74   nmethod* nm = c._nmethods[id];
  75   depContext.remove_dependent_nmethod(nm, delete_immediately);
  76 
  77   if (!delete_immediately) {
  78     NOT_PRODUCT(ASSERT_TRUE(TestDependencyContext::find_stale_entries(depContext)));
  79     ASSERT_TRUE(TestDependencyContext::has_stale_entries(depContext));
  80     NOT_PRODUCT(ASSERT_TRUE(depContext.is_dependent_nmethod(nm)));
  81     depContext.expunge_stale_entries();
  82   }
  83 
  84   NOT_PRODUCT(ASSERT_FALSE(TestDependencyContext::find_stale_entries(depContext)));
  85   ASSERT_FALSE(TestDependencyContext::has_stale_entries(depContext));


  33   intptr_t _dependency_context;
  34 
  35   DependencyContext dependencies() {
  36     DependencyContext depContext(&_dependency_context);
  37     return depContext;
  38   }
  39 
  40   TestDependencyContext() : _dependency_context(DependencyContext::EMPTY) {
  41     CodeCache_lock->lock_without_safepoint_check();
  42 
  43     _nmethods[0] = reinterpret_cast<nmethod*>(0x8 * 0);
  44     _nmethods[1] = reinterpret_cast<nmethod*>(0x8 * 1);
  45     _nmethods[2] = reinterpret_cast<nmethod*>(0x8 * 2);
  46 
  47     dependencies().add_dependent_nmethod(_nmethods[2]);
  48     dependencies().add_dependent_nmethod(_nmethods[1]);
  49     dependencies().add_dependent_nmethod(_nmethods[0]);
  50   }
  51 
  52   ~TestDependencyContext() {
  53     wipe();
  54     CodeCache_lock->unlock();
  55   }
  56 
  57   static bool has_stale_entries(DependencyContext ctx) {
  58     return ctx.has_stale_entries();
  59   }
  60 
  61 #ifndef PRODUCT
  62   static bool find_stale_entries(DependencyContext ctx) {
  63     return ctx.find_stale_entries();
  64   }
  65 #endif
  66 
  67   void wipe() {
  68     DependencyContext ctx(&_dependency_context);
  69     nmethodBucket* b = ctx.dependencies();
  70     ctx.set_dependencies(NULL);
  71     ctx.set_has_stale_entries(false);
  72     while (b != NULL) {
  73       nmethodBucket* next = b->next();
  74       delete b;
  75       b = next;
  76     }
  77   }
  78 };
  79 
  80 static void test_remove_dependent_nmethod(int id, bool delete_immediately) {
  81   TestDependencyContext c;
  82   DependencyContext depContext = c.dependencies();
  83   NOT_PRODUCT(ASSERT_FALSE(TestDependencyContext::find_stale_entries(depContext)));
  84   ASSERT_FALSE(TestDependencyContext::has_stale_entries(depContext));
  85 
  86   nmethod* nm = c._nmethods[id];
  87   depContext.remove_dependent_nmethod(nm, delete_immediately);
  88 
  89   if (!delete_immediately) {
  90     NOT_PRODUCT(ASSERT_TRUE(TestDependencyContext::find_stale_entries(depContext)));
  91     ASSERT_TRUE(TestDependencyContext::has_stale_entries(depContext));
  92     NOT_PRODUCT(ASSERT_TRUE(depContext.is_dependent_nmethod(nm)));
  93     depContext.expunge_stale_entries();
  94   }
  95 
  96   NOT_PRODUCT(ASSERT_FALSE(TestDependencyContext::find_stale_entries(depContext)));
  97   ASSERT_FALSE(TestDependencyContext::has_stale_entries(depContext));
< prev index next >