< prev index next >

test/hotspot/gtest/code/test_dependencyContext.cpp


10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License                                                             
11  * version 2 for more details (a copy is included in the LICENSE file that                                                           
12  * accompanied this code).                                                                                                           
13  *                                                                                                                                   
14  * You should have received a copy of the GNU General Public License version                                                         
15  * 2 along with this work; if not, write to the Free Software Foundation,                                                            
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.                                                                     
17  *                                                                                                                                   
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA                                                           
19  * or visit www.oracle.com if you need additional information or have any                                                            
20  * questions.                                                                                                                        
21  *                                                                                                                                   
22  */                                                                                                                                  
23 
24 #include "precompiled.hpp"                                                                                                           
25 #include "code/dependencyContext.hpp"                                                                                                
26 #include "unittest.hpp"                                                                                                              
27 
28 class TestDependencyContext {                                                                                                        
29  public:                                                                                                                             
                                                                                                                                     
30   nmethod* _nmethods[3];                                                                                                             
31 
32   intptr_t _dependency_context;                                                                                                      
                                                                                                                                     
33 
34   DependencyContext dependencies() {                                                                                                 
35     DependencyContext depContext(&_dependency_context);                                                                              
36     return depContext;                                                                                                               
37   }                                                                                                                                  
38 
39   TestDependencyContext() : _dependency_context(DependencyContext::EMPTY) {                                                          
                                                                                                                                     
                                                                                                                                     
40     CodeCache_lock->lock_without_safepoint_check();                                                                                  
41 
42     _nmethods[0] = reinterpret_cast<nmethod*>(0x8 * 0);                                                                              
43     _nmethods[1] = reinterpret_cast<nmethod*>(0x8 * 1);                                                                              
44     _nmethods[2] = reinterpret_cast<nmethod*>(0x8 * 2);                                                                              
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
45 
46     dependencies().add_dependent_nmethod(_nmethods[2]);                                                                              
47     dependencies().add_dependent_nmethod(_nmethods[1]);                                                                              
48     dependencies().add_dependent_nmethod(_nmethods[0]);                                                                              
49   }                                                                                                                                  
50 
51   ~TestDependencyContext() {                                                                                                         
52     wipe();                                                                                                                          
53     CodeCache_lock->unlock();                                                                                                        
54   }                                                                                                                                  
55 
56   static bool has_stale_entries(DependencyContext ctx) {                                                                             
57     return ctx.has_stale_entries();                                                                                                  
58   }                                                                                                                                  
59                                                                                                                                      
60 #ifndef PRODUCT                                                                                                                      
61   static bool find_stale_entries(DependencyContext ctx) {                                                                            
62     return ctx.find_stale_entries();                                                                                                 
63   }                                                                                                                                  
64 #endif                                                                                                                               
65                                                                                                                                      
66   void wipe() {                                                                                                                      
67     DependencyContext ctx(&_dependency_context);                                                                                     
68     nmethodBucket* b = ctx.dependencies();                                                                                           
69     ctx.set_dependencies(NULL);                                                                                                      
70     ctx.set_has_stale_entries(false);                                                                                                
71     while (b != NULL) {                                                                                                              
72       nmethodBucket* next = b->next();                                                                                               
73       delete b;                                                                                                                      
74       b = next;                                                                                                                      
75     }                                                                                                                                
76   }                                                                                                                                  
77 };                                                                                                                                   
78 
79 static void test_remove_dependent_nmethod(int id, bool delete_immediately) {                                                         
80   TestDependencyContext c;                                                                                                           
81   DependencyContext depContext = c.dependencies();                                                                                   
82   NOT_PRODUCT(ASSERT_FALSE(TestDependencyContext::find_stale_entries(depContext)));                                                  
83   ASSERT_FALSE(TestDependencyContext::has_stale_entries(depContext));                                                                
84 
85   nmethod* nm = c._nmethods[id];                                                                                                     
86   depContext.remove_dependent_nmethod(nm, delete_immediately);                                                                       
87                                                                                                                                      
88   if (!delete_immediately) {                                                                                                         
89     NOT_PRODUCT(ASSERT_TRUE(TestDependencyContext::find_stale_entries(depContext)));                                                 
90     ASSERT_TRUE(TestDependencyContext::has_stale_entries(depContext));                                                               
91     NOT_PRODUCT(ASSERT_TRUE(depContext.is_dependent_nmethod(nm)));                                                                   
92     depContext.expunge_stale_entries();                                                                                              
93   }                                                                                                                                  
94 
95   NOT_PRODUCT(ASSERT_FALSE(TestDependencyContext::find_stale_entries(depContext)));                                                  
96   ASSERT_FALSE(TestDependencyContext::has_stale_entries(depContext));                                                                
97   NOT_PRODUCT(ASSERT_FALSE(depContext.is_dependent_nmethod(nm)));                                                                    
98 }                                                                                                                                    
99 
100 TEST_VM(code, dependency_context) {                                                                                                  
101   test_remove_dependent_nmethod(0, false);                                                                                           
102   test_remove_dependent_nmethod(1, false);                                                                                           
103   test_remove_dependent_nmethod(2, false);                                                                                           
104                                                                                                                                      
105   test_remove_dependent_nmethod(0, true);                                                                                            
106   test_remove_dependent_nmethod(1, true);                                                                                            
107   test_remove_dependent_nmethod(2, true);                                                                                            
108 }                                                                                                                                    

10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * version 2 for more details (a copy is included in the LICENSE file that
12  * accompanied this code).
13  *
14  * You should have received a copy of the GNU General Public License version
15  * 2 along with this work; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19  * or visit www.oracle.com if you need additional information or have any
20  * questions.
21  *
22  */
23 
24 #include "precompiled.hpp"
25 #include "code/dependencyContext.hpp"
26 #include "unittest.hpp"
27 
28 class TestDependencyContext {
29  public:
30   char* _buffer[sizeof(nmethod) * 3];
31   nmethod* _nmethods[3];
32 
33   nmethodBucket* volatile _dependency_context;
34   volatile uint64_t _last_cleanup;
35 
36   DependencyContext dependencies() {
37     DependencyContext depContext(&_dependency_context, &_last_cleanup);
38     return depContext;
39   }
40 
41   TestDependencyContext()
42     : _dependency_context(NULL),
43       _last_cleanup(0) {
44     CodeCache_lock->lock_without_safepoint_check();
45 
46     memset(_buffer, 0, sizeof(nmethod) * 3);
47     _nmethods[0] = reinterpret_cast<nmethod*>(_buffer) + 0;
48     _nmethods[1] = reinterpret_cast<nmethod*>(_buffer) + 1;
49     _nmethods[2] = reinterpret_cast<nmethod*>(_buffer) + 2;
50 
51     _nmethods[0]->clear_unloading_state();
52     _nmethods[1]->clear_unloading_state();
53     _nmethods[2]->clear_unloading_state();
54 
55     dependencies().add_dependent_nmethod(_nmethods[2]);
56     dependencies().add_dependent_nmethod(_nmethods[1]);
57     dependencies().add_dependent_nmethod(_nmethods[0]);
58   }
59 
60   ~TestDependencyContext() {
61     wipe();
62     CodeCache_lock->unlock();
63   }
64 










65   void wipe() {
66     DependencyContext ctx(&_dependency_context, &_last_cleanup);
67     nmethodBucket* b = ctx.dependencies();
68     ctx.set_dependencies(NULL);

69     while (b != NULL) {
70       nmethodBucket* next = b->next();
71       delete b;
72       b = next;
73     }
74   }
75 };
76 
77 static void test_remove_dependent_nmethod(int id) {
78   TestDependencyContext c;
79   DependencyContext depContext = c.dependencies();


80 
81   nmethod* nm = c._nmethods[id];
82   depContext.remove_dependent_nmethod(nm);







83 


84   NOT_PRODUCT(ASSERT_FALSE(depContext.is_dependent_nmethod(nm)));
85 }
86 
87 TEST_VM(code, dependency_context) {
88   test_remove_dependent_nmethod(0);
89   test_remove_dependent_nmethod(1);
90   test_remove_dependent_nmethod(2);




91 }
< prev index next >