@@ -52,12 +52,6 @@ struct debug_link_info {
5252 uint32_t crc32;
5353};
5454
55- extern " C" JL_DLLEXPORT void jl_lock_profile_impl (void ) JL_NOTSAFEPOINT;
56- extern " C" JL_DLLEXPORT void jl_unlock_profile_impl (void ) JL_NOTSAFEPOINT;
57-
58- template <typename T>
59- static void jl_profile_atomic (T f);
60-
6155#if (defined(_OS_LINUX_) || defined(_OS_FREEBSD_) || (defined(_OS_DARWIN_) && defined(LLVM_SHLIB)))
6256extern " C" void __register_frame (void *);
6357extern " C" void __deregister_frame (void *);
@@ -101,16 +95,16 @@ void JITDebugInfoRegistry::add_code_in_flight(StringRef name, jl_code_instance_t
10195
10296jl_method_instance_t *JITDebugInfoRegistry::lookupLinfo (size_t pointer) JL_NOTSAFEPOINT
10397{
104- jl_lock_profile_impl ();
98+ jl_lock_profile ();
10599 auto region = linfomap.lower_bound (pointer);
106100 jl_method_instance_t *linfo = NULL ;
107101 if (region != linfomap.end () && pointer < region->first + region->second .first )
108102 linfo = region->second .second ;
109- jl_unlock_profile_impl ();
103+ jl_unlock_profile ();
110104 return linfo;
111105}
112106
113- // Protected by debuginfo_asyncsafe
107+ // Protected by debuginfo_asyncsafe (profile) lock
114108JITDebugInfoRegistry::objectmap_t &
115109JITDebugInfoRegistry::getObjectMap () JL_NOTSAFEPOINT
116110{
@@ -131,41 +125,21 @@ JITDebugInfoRegistry::get_objfile_map() JL_NOTSAFEPOINT {
131125 return *this ->objfilemap ;
132126}
133127
134- JITDebugInfoRegistry::JITDebugInfoRegistry () JL_NOTSAFEPOINT {
135- uv_rwlock_init (&debuginfo_asyncsafe);
136- debuginfo_asyncsafe_held.init ();
137- }
128+ JITDebugInfoRegistry::JITDebugInfoRegistry () JL_NOTSAFEPOINT { }
138129
139130struct unw_table_entry
140131{
141132 int32_t start_ip_offset;
142133 int32_t fde_offset;
143134};
144135
145- extern " C" JL_DLLEXPORT void jl_lock_profile_impl (void ) JL_NOTSAFEPOINT
146- {
147- uintptr_t held = getJITDebugRegistry ().debuginfo_asyncsafe_held ;
148- if (held++ == 0 )
149- uv_rwlock_rdlock (&getJITDebugRegistry ().debuginfo_asyncsafe );
150- getJITDebugRegistry ().debuginfo_asyncsafe_held = held;
151- }
152-
153- extern " C" JL_DLLEXPORT void jl_unlock_profile_impl (void ) JL_NOTSAFEPOINT
154- {
155- uintptr_t held = getJITDebugRegistry ().debuginfo_asyncsafe_held ;
156- assert (held);
157- if (--held == 0 )
158- uv_rwlock_rdunlock (&getJITDebugRegistry ().debuginfo_asyncsafe );
159- getJITDebugRegistry ().debuginfo_asyncsafe_held = held;
160- }
161-
162136// some actions aren't signal (especially profiler) safe so we acquire a lock
163137// around them to establish a mutual exclusion with unwinding from a signal
164138template <typename T>
165139static void jl_profile_atomic (T f)
166140{
167- assert (0 == getJITDebugRegistry (). debuginfo_asyncsafe_held );
168- uv_rwlock_wrlock (& getJITDebugRegistry (). debuginfo_asyncsafe );
141+ assert (0 == jl_lock_profile_rd_held () );
142+ jl_lock_profile_wr ( );
169143#ifndef _OS_WINDOWS_
170144 sigset_t sset;
171145 sigset_t oset;
@@ -176,7 +150,7 @@ static void jl_profile_atomic(T f)
176150#ifndef _OS_WINDOWS_
177151 pthread_sigmask (SIG_SETMASK, &oset, NULL );
178152#endif
179- uv_rwlock_wrunlock (& getJITDebugRegistry (). debuginfo_asyncsafe );
153+ jl_unlock_profile_wr ( );
180154}
181155
182156
@@ -482,10 +456,10 @@ static int lookup_pointer(
482456
483457 // DWARFContext/DWARFUnit update some internal tables during these queries, so
484458 // a lock is needed.
485- assert (0 == getJITDebugRegistry (). debuginfo_asyncsafe_held );
486- uv_rwlock_wrlock (& getJITDebugRegistry (). debuginfo_asyncsafe );
459+ assert (0 == jl_lock_profile_rd_held () );
460+ jl_lock_profile_wr ( );
487461 auto inlineInfo = context->getInliningInfoForAddress (makeAddress (Section, pointer + slide), infoSpec);
488- uv_rwlock_wrunlock (& getJITDebugRegistry (). debuginfo_asyncsafe );
462+ jl_unlock_profile_wr ( );
489463
490464 int fromC = (*frames)[0 ].fromC ;
491465 int n_frames = inlineInfo.getNumberOfFrames ();
@@ -508,9 +482,9 @@ static int lookup_pointer(
508482 info = inlineInfo.getFrame (i);
509483 }
510484 else {
511- uv_rwlock_wrlock (& getJITDebugRegistry (). debuginfo_asyncsafe );
485+ jl_lock_profile_wr ( );
512486 info = context->getLineInfoForAddress (makeAddress (Section, pointer + slide), infoSpec);
513- uv_rwlock_wrunlock (& getJITDebugRegistry (). debuginfo_asyncsafe );
487+ jl_unlock_profile_wr ( );
514488 }
515489
516490 jl_frame_t *frame = &(*frames)[i];
@@ -1197,8 +1171,9 @@ int jl_DI_for_fptr(uint64_t fptr, uint64_t *symsize, int64_t *slide,
11971171 object::SectionRef *Section, llvm::DIContext **context) JL_NOTSAFEPOINT
11981172{
11991173 int found = 0 ;
1200- assert (0 == getJITDebugRegistry ().debuginfo_asyncsafe_held );
1201- uv_rwlock_wrlock (&getJITDebugRegistry ().debuginfo_asyncsafe );
1174+ assert (0 == jl_lock_profile_rd_held ());
1175+ jl_lock_profile_wr ();
1176+
12021177 if (symsize)
12031178 *symsize = 0 ;
12041179
@@ -1214,7 +1189,7 @@ int jl_DI_for_fptr(uint64_t fptr, uint64_t *symsize, int64_t *slide,
12141189 }
12151190 found = 1 ;
12161191 }
1217- uv_rwlock_wrunlock (& getJITDebugRegistry (). debuginfo_asyncsafe );
1192+ jl_unlock_profile_wr ( );
12181193 return found;
12191194}
12201195
@@ -1613,13 +1588,13 @@ extern "C" JL_DLLEXPORT
16131588uint64_t jl_getUnwindInfo_impl (uint64_t dwAddr)
16141589{
16151590 // Might be called from unmanaged thread
1616- jl_lock_profile_impl ();
1591+ jl_lock_profile ();
16171592 auto &objmap = getJITDebugRegistry ().getObjectMap ();
16181593 auto it = objmap.lower_bound (dwAddr);
16191594 uint64_t ipstart = 0 ; // ip of the start of the section (if found)
16201595 if (it != objmap.end () && dwAddr < it->first + it->second .SectionSize ) {
16211596 ipstart = (uint64_t )(uintptr_t )(*it).first ;
16221597 }
1623- jl_unlock_profile_impl ();
1598+ jl_unlock_profile ();
16241599 return ipstart;
16251600}
0 commit comments