1 /*
  2  * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2021, Azul Systems, Inc. All rights reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #include "precompiled.hpp"
 27 #include "classfile/javaClasses.hpp"
 28 #include "classfile/javaThreadStatus.hpp"
 29 #include "gc/shared/barrierSet.hpp"
 30 #include "jfr/jfrEvents.hpp"
 31 #include "jvm.h"
 32 #include "jvmtifiles/jvmtiEnv.hpp"
 33 #include "logging/log.hpp"
 34 #include "memory/allocation.inline.hpp"
 35 #include "memory/iterator.hpp"
 36 #include "memory/resourceArea.hpp"
 37 #include "nmt/memTracker.hpp"
 38 #include "oops/oop.inline.hpp"
 39 #include "runtime/atomic.hpp"
 40 #include "runtime/handles.inline.hpp"
 41 #include "runtime/javaThread.inline.hpp"
 42 #include "runtime/nonJavaThread.hpp"
 43 #include "runtime/orderAccess.hpp"
 44 #include "runtime/osThread.hpp"
 45 #include "runtime/safepoint.hpp"
 46 #include "runtime/safepointMechanism.inline.hpp"
 47 #include "runtime/thread.inline.hpp"
 48 #include "runtime/threadSMR.inline.hpp"
 49 #include "utilities/macros.hpp"
 50 #include "utilities/spinYield.hpp"
 51 #if INCLUDE_JFR
 52 #include "jfr/jfr.hpp"
 53 #endif
 54 
 55 #ifndef USE_LIBRARY_BASED_TLS_ONLY
 56 // Current thread is maintained as a thread-local variable
 57 THREAD_LOCAL Thread* Thread::_thr_current = nullptr;
 58 #endif
 59 
 60 // ======= Thread ========
 61 // Base class for all threads: VMThread, WatcherThread, ConcurrentMarkSweepThread,
 62 // JavaThread
 63 
 64 DEBUG_ONLY(Thread* Thread::_starting_thread = nullptr;)
 65 
 66 Thread::Thread() {
 67 
 68   DEBUG_ONLY(_run_state = PRE_CALL_RUN;)
 69 
 70   // stack and get_thread
 71   set_stack_base(nullptr);
 72   set_stack_size(0);
 73   set_lgrp_id(-1);
 74   DEBUG_ONLY(clear_suspendible_thread();)
 75   DEBUG_ONLY(clear_indirectly_suspendible_thread();)
 76   DEBUG_ONLY(clear_indirectly_safepoint_thread();)
 77 
 78   // allocated data structures
 79   set_osthread(nullptr);
 80   set_resource_area(new (mtThread)ResourceArea());
 81   DEBUG_ONLY(_current_resource_mark = nullptr;)
 82   set_handle_area(new (mtThread) HandleArea(nullptr));
 83   set_metadata_handles(new (mtClass) GrowableArray<Metadata*>(30, mtClass));
 84   set_last_handle_mark(nullptr);
 85   DEBUG_ONLY(_missed_ic_stub_refill_verifier = nullptr);
 86 
 87   // Initial value of zero ==> never claimed.
 88   _threads_do_token = 0;
 89   _threads_hazard_ptr = nullptr;
 90   _threads_list_ptr = nullptr;
 91   _nested_threads_hazard_ptr_cnt = 0;
 92   _rcu_counter = 0;
 93 
 94   // the handle mark links itself to last_handle_mark
 95   new HandleMark(this);
 96 
 97   // plain initialization
 98   debug_only(_owned_locks = nullptr;)
 99   NOT_PRODUCT(_skip_gcalot = false;)
100   _jvmti_env_iteration_count = 0;
101   set_allocated_bytes(0);
102   _current_pending_raw_monitor = nullptr;
103   _vm_error_callbacks = nullptr;
104 
105   // thread-specific hashCode stream generator state - Marsaglia shift-xor form
106   _hashStateX = os::random();
107   _hashStateY = 842502087;
108   _hashStateZ = 0x8767;    // (int)(3579807591LL & 0xffff) ;
109   _hashStateW = 273326509;
110 
111   // Many of the following fields are effectively final - immutable
112   // Note that nascent threads can't use the Native Monitor-Mutex
113   // construct until the _MutexEvent is initialized ...
114   // CONSIDER: instead of using a fixed set of purpose-dedicated ParkEvents
115   // we might instead use a stack of ParkEvents that we could provision on-demand.
116   // The stack would act as a cache to avoid calls to ParkEvent::Allocate()
117   // and ::Release()
118   _ParkEvent   = ParkEvent::Allocate(this);
119 
120 #ifdef CHECK_UNHANDLED_OOPS
121   if (CheckUnhandledOops) {
122     _unhandled_oops = new UnhandledOops(this);
123   }
124 #endif // CHECK_UNHANDLED_OOPS
125 
126   // Notify the barrier set that a thread is being created. The initial
127   // thread is created before the barrier set is available.  The call to
128   // BarrierSet::on_thread_create() for this thread is therefore deferred
129   // to BarrierSet::set_barrier_set().
130   BarrierSet* const barrier_set = BarrierSet::barrier_set();
131   if (barrier_set != nullptr) {
132     barrier_set->on_thread_create(this);
133   } else {
134     // Only the main thread should be created before the barrier set
135     // and that happens just before Thread::current is set. No other thread
136     // can attach as the VM is not created yet, so they can't execute this code.
137     // If the main thread creates other threads before the barrier set that is an error.
138     assert(Thread::current_or_null() == nullptr, "creating thread before barrier set");
139   }
140 
141   MACOS_AARCH64_ONLY(DEBUG_ONLY(_wx_init = false));
142 }
143 
144 void Thread::initialize_tlab() {
145   if (UseTLAB) {
146     tlab().initialize();
147   }
148 }
149 
150 void Thread::initialize_thread_current() {
151 #ifndef USE_LIBRARY_BASED_TLS_ONLY
152   assert(_thr_current == nullptr, "Thread::current already initialized");
153   _thr_current = this;
154 #endif
155   assert(ThreadLocalStorage::thread() == nullptr, "ThreadLocalStorage::thread already initialized");
156   ThreadLocalStorage::set_thread(this);
157   assert(Thread::current() == ThreadLocalStorage::thread(), "TLS mismatch!");
158 }
159 
160 void Thread::clear_thread_current() {
161   assert(Thread::current() == ThreadLocalStorage::thread(), "TLS mismatch!");
162 #ifndef USE_LIBRARY_BASED_TLS_ONLY
163   _thr_current = nullptr;
164 #endif
165   ThreadLocalStorage::set_thread(nullptr);
166 }
167 
168 void Thread::record_stack_base_and_size() {
169   // Note: at this point, Thread object is not yet initialized. Do not rely on
170   // any members being initialized. Do not rely on Thread::current() being set.
171   // If possible, refrain from doing anything which may crash or assert since
172   // quite probably those crash dumps will be useless.
173   address base;
174   size_t size;
175   os::current_stack_base_and_size(&base, &size);
176   set_stack_base(base);
177   set_stack_size(size);
178 
179   // Set stack limits after thread is initialized.
180   if (is_Java_thread()) {
181     JavaThread::cast(this)->stack_overflow_state()->initialize(stack_base(), stack_end());
182   }
183 }
184 
185 void Thread::register_thread_stack_with_NMT() {
186   MemTracker::record_thread_stack(stack_end(), stack_size());
187 }
188 
189 void Thread::unregister_thread_stack_with_NMT() {
190   MemTracker::release_thread_stack(stack_end(), stack_size());
191 }
192 
193 void Thread::call_run() {
194   DEBUG_ONLY(_run_state = CALL_RUN;)
195 
196   // At this point, Thread object should be fully initialized and
197   // Thread::current() should be set.
198 
199   assert(Thread::current_or_null() != nullptr, "current thread is unset");
200   assert(Thread::current_or_null() == this, "current thread is wrong");
201 
202   // Perform common initialization actions
203 
204   MACOS_AARCH64_ONLY(this->init_wx());
205 
206   register_thread_stack_with_NMT();
207 
208   JFR_ONLY(Jfr::on_thread_start(this);)
209 
210   log_debug(os, thread)("Thread " UINTX_FORMAT " stack dimensions: "
211     PTR_FORMAT "-" PTR_FORMAT " (" SIZE_FORMAT "k).",
212     os::current_thread_id(), p2i(stack_end()),
213     p2i(stack_base()), stack_size()/1024);
214 
215   // Perform <ChildClass> initialization actions
216   DEBUG_ONLY(_run_state = PRE_RUN;)
217   this->pre_run();
218 
219   // Invoke <ChildClass>::run()
220   DEBUG_ONLY(_run_state = RUN;)
221   this->run();
222   // Returned from <ChildClass>::run(). Thread finished.
223 
224   // Perform common tear-down actions
225 
226   assert(Thread::current_or_null() != nullptr, "current thread is unset");
227   assert(Thread::current_or_null() == this, "current thread is wrong");
228 
229   // Perform <ChildClass> tear-down actions
230   DEBUG_ONLY(_run_state = POST_RUN;)
231   this->post_run();
232 
233   // Note: at this point the thread object may already have deleted itself,
234   // so from here on do not dereference *this*. Not all thread types currently
235   // delete themselves when they terminate. But no thread should ever be deleted
236   // asynchronously with respect to its termination - that is what _run_state can
237   // be used to check.
238 
239   assert(Thread::current_or_null() == nullptr, "current thread still present");
240 }
241 
242 Thread::~Thread() {
243 
244   // Attached threads will remain in PRE_CALL_RUN, as will threads that don't actually
245   // get started due to errors etc. Any active thread should at least reach post_run
246   // before it is deleted (usually in post_run()).
247   assert(_run_state == PRE_CALL_RUN ||
248          _run_state == POST_RUN, "Active Thread deleted before post_run(): "
249          "_run_state=%d", (int)_run_state);
250 
251   // Notify the barrier set that a thread is being destroyed. Note that a barrier
252   // set might not be available if we encountered errors during bootstrapping.
253   BarrierSet* const barrier_set = BarrierSet::barrier_set();
254   if (barrier_set != nullptr) {
255     barrier_set->on_thread_destroy(this);
256   }
257 
258   // deallocate data structures
259   delete resource_area();
260   // since the handle marks are using the handle area, we have to deallocated the root
261   // handle mark before deallocating the thread's handle area,
262   assert(last_handle_mark() != nullptr, "check we have an element");
263   delete last_handle_mark();
264   assert(last_handle_mark() == nullptr, "check we have reached the end");
265 
266   ParkEvent::Release(_ParkEvent);
267   // Set to null as a termination indicator for has_terminated().
268   Atomic::store(&_ParkEvent, (ParkEvent*)nullptr);
269 
270   delete handle_area();
271   delete metadata_handles();
272 
273   // osthread() can be null, if creation of thread failed.
274   if (osthread() != nullptr) os::free_thread(osthread());
275 
276   // Clear Thread::current if thread is deleting itself and it has not
277   // already been done. This must be done before the memory is deallocated.
278   // Needed to ensure JNI correctly detects non-attached threads.
279   if (this == Thread::current_or_null()) {
280     Thread::clear_thread_current();
281   }
282 
283   CHECK_UNHANDLED_OOPS_ONLY(if (CheckUnhandledOops) delete unhandled_oops();)
284 }
285 
286 #ifdef ASSERT
287 // A JavaThread is considered dangling if it not handshake-safe with respect to
288 // the current thread, it is not on a ThreadsList, or not at safepoint.
289 void Thread::check_for_dangling_thread_pointer(Thread *thread) {
290   assert(!thread->is_Java_thread() ||
291          JavaThread::cast(thread)->is_handshake_safe_for(Thread::current()) ||
292          !JavaThread::cast(thread)->on_thread_list() ||
293          SafepointSynchronize::is_at_safepoint() ||
294          ThreadsSMRSupport::is_a_protected_JavaThread_with_lock(JavaThread::cast(thread)),
295          "possibility of dangling Thread pointer");
296 }
297 #endif
298 
299 // Is the target JavaThread protected by the calling Thread or by some other
300 // mechanism?
301 //
302 bool Thread::is_JavaThread_protected(const JavaThread* target) {
303   Thread* current_thread = Thread::current();
304 
305   // Do the simplest check first:
306   if (SafepointSynchronize::is_at_safepoint()) {
307     // The target is protected since JavaThreads cannot exit
308     // while we're at a safepoint.
309     return true;
310   }
311 
312   // If the target hasn't been started yet then it is trivially
313   // "protected". We assume the caller is the thread that will do
314   // the starting.
315   if (target->osthread() == nullptr || target->osthread()->get_state() <= INITIALIZED) {
316     return true;
317   }
318 
319   // Now make the simple checks based on who the caller is:
320   if (current_thread == target || Threads_lock->owner() == current_thread) {
321     // Target JavaThread is self or calling thread owns the Threads_lock.
322     // Second check is the same as Threads_lock->owner_is_self(),
323     // but we already have the current thread so check directly.
324     return true;
325   }
326 
327   // Check the ThreadsLists associated with the calling thread (if any)
328   // to see if one of them protects the target JavaThread:
329   if (is_JavaThread_protected_by_TLH(target)) {
330     return true;
331   }
332 
333   // Use this debug code with -XX:+UseNewCode to diagnose locations that
334   // are missing a ThreadsListHandle or other protection mechanism:
335   // guarantee(!UseNewCode, "current_thread=" INTPTR_FORMAT " is not protecting target="
336   //           INTPTR_FORMAT, p2i(current_thread), p2i(target));
337 
338   // Note: Since 'target' isn't protected by a TLH, the call to
339   // target->is_handshake_safe_for() may crash, but we have debug bits so
340   // we'll be able to figure out what protection mechanism is missing.
341   assert(target->is_handshake_safe_for(current_thread), "JavaThread=" INTPTR_FORMAT
342          " is not protected and not handshake safe.", p2i(target));
343 
344   // The target JavaThread is not protected so it is not safe to query:
345   return false;
346 }
347 
348 // Is the target JavaThread protected by a ThreadsListHandle (TLH) associated
349 // with the calling Thread?
350 //
351 bool Thread::is_JavaThread_protected_by_TLH(const JavaThread* target) {
352   Thread* current_thread = Thread::current();
353 
354   // Check the ThreadsLists associated with the calling thread (if any)
355   // to see if one of them protects the target JavaThread:
356   for (SafeThreadsListPtr* stlp = current_thread->_threads_list_ptr;
357        stlp != nullptr; stlp = stlp->previous()) {
358     if (stlp->list()->includes(target)) {
359       // The target JavaThread is protected by this ThreadsList:
360       return true;
361     }
362   }
363 
364   // The target JavaThread is not protected by a TLH so it is not safe to query:
365   return false;
366 }
367 
368 void Thread::set_priority(Thread* thread, ThreadPriority priority) {
369   debug_only(check_for_dangling_thread_pointer(thread);)
370   // Can return an error!
371   (void)os::set_priority(thread, priority);
372 }
373 
374 
375 void Thread::start(Thread* thread) {
376   // Start is different from resume in that its safety is guaranteed by context or
377   // being called from a Java method synchronized on the Thread object.
378   if (thread->is_Java_thread()) {
379     // Initialize the thread state to RUNNABLE before starting this thread.
380     // Can not set it after the thread started because we do not know the
381     // exact thread state at that time. It could be in MONITOR_WAIT or
382     // in SLEEPING or some other state.
383     java_lang_Thread::set_thread_status(JavaThread::cast(thread)->threadObj(),
384                                         JavaThreadStatus::RUNNABLE);
385   }
386   os::start_thread(thread);
387 }
388 
389 // GC Support
390 bool Thread::claim_par_threads_do(uintx claim_token) {
391   uintx token = _threads_do_token;
392   if (token != claim_token) {
393     uintx res = Atomic::cmpxchg(&_threads_do_token, token, claim_token);
394     if (res == token) {
395       return true;
396     }
397     guarantee(res == claim_token, "invariant");
398   }
399   return false;
400 }
401 
402 void Thread::oops_do_no_frames(OopClosure* f, CodeBlobClosure* cf) {
403   // Do oop for ThreadShadow
404   f->do_oop((oop*)&_pending_exception);
405   handle_area()->oops_do(f);
406 }
407 
408 // If the caller is a NamedThread, then remember, in the current scope,
409 // the given JavaThread in its _processed_thread field.
410 class RememberProcessedThread: public StackObj {
411   NamedThread* _cur_thr;
412 public:
413   RememberProcessedThread(Thread* thread) {
414     Thread* self = Thread::current();
415     if (self->is_Named_thread()) {
416       _cur_thr = (NamedThread *)self;
417       assert(_cur_thr->processed_thread() == nullptr, "nesting not supported");
418       _cur_thr->set_processed_thread(thread);
419     } else {
420       _cur_thr = nullptr;
421     }
422   }
423 
424   ~RememberProcessedThread() {
425     if (_cur_thr) {
426       assert(_cur_thr->processed_thread() != nullptr, "nesting not supported");
427       _cur_thr->set_processed_thread(nullptr);
428     }
429   }
430 };
431 
432 void Thread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
433   // Record JavaThread to GC thread
434   RememberProcessedThread rpt(this);
435   oops_do_no_frames(f, cf);
436   oops_do_frames(f, cf);
437 }
438 
439 void Thread::metadata_handles_do(void f(Metadata*)) {
440   // Only walk the Handles in Thread.
441   if (metadata_handles() != nullptr) {
442     for (int i = 0; i< metadata_handles()->length(); i++) {
443       f(metadata_handles()->at(i));
444     }
445   }
446 }
447 
448 void Thread::print_on(outputStream* st, bool print_extended_info) const {
449   // get_priority assumes osthread initialized
450   if (osthread() != nullptr) {
451     int os_prio;
452     if (os::get_native_priority(this, &os_prio) == OS_OK) {
453       st->print("os_prio=%d ", os_prio);
454     }
455 
456     st->print("cpu=%.2fms ",
457               (double)os::thread_cpu_time(const_cast<Thread*>(this), true) / 1000000.0
458               );
459     st->print("elapsed=%.2fs ",
460               (double)_statistical_info.getElapsedTime() / 1000.0
461               );
462     if (is_Java_thread() && (PrintExtendedThreadInfo || print_extended_info)) {
463       size_t allocated_bytes = (size_t) const_cast<Thread*>(this)->cooked_allocated_bytes();
464       st->print("allocated=" SIZE_FORMAT "%s ",
465                 byte_size_in_proper_unit(allocated_bytes),
466                 proper_unit_for_byte_size(allocated_bytes)
467                 );
468       st->print("defined_classes=" INT64_FORMAT " ", _statistical_info.getDefineClassCount());
469     }
470 
471     st->print("tid=" INTPTR_FORMAT " ", p2i(this));
472     if (!is_Java_thread() || !JavaThread::cast(this)->is_vthread_mounted()) {
473       osthread()->print_on(st);
474     }
475   }
476   ThreadsSMRSupport::print_info_on(this, st);
477   st->print(" ");
478   debug_only(if (WizardMode) print_owned_locks_on(st);)
479 }
480 
481 void Thread::print() const { print_on(tty); }
482 
483 // Thread::print_on_error() is called by fatal error handler. Don't use
484 // any lock or allocate memory.
485 void Thread::print_on_error(outputStream* st, char* buf, int buflen) const {
486   assert(!(is_Compiler_thread() || is_Java_thread()), "Can't call name() here if it allocates");
487 
488   st->print("%s \"%s\"", type_name(), name());
489 
490   OSThread* os_thr = osthread();
491   if (os_thr != nullptr) {
492     st->fill_to(67);
493     if (os_thr->get_state() != ZOMBIE) {
494       st->print(" [id=%d, stack(" PTR_FORMAT "," PTR_FORMAT ") (" PROPERFMT ")]",
495                 osthread()->thread_id(), p2i(stack_end()), p2i(stack_base()),
496                 PROPERFMTARGS(stack_size()));
497     } else {
498       st->print(" terminated");
499     }
500   } else {
501     st->print(" unknown state (no osThread)");
502   }
503   ThreadsSMRSupport::print_info_on(this, st);
504 }
505 
506 void Thread::print_value_on(outputStream* st) const {
507   if (is_Named_thread()) {
508     st->print(" \"%s\" ", name());
509   }
510   st->print(INTPTR_FORMAT, p2i(this));   // print address
511 }
512 
513 #ifdef ASSERT
514 void Thread::print_owned_locks_on(outputStream* st) const {
515   Mutex* cur = _owned_locks;
516   if (cur == nullptr) {
517     st->print(" (no locks) ");
518   } else {
519     st->print_cr(" Locks owned:");
520     while (cur) {
521       cur->print_on(st);
522       cur = cur->next();
523     }
524   }
525 }
526 #endif // ASSERT
527 
528 // We had to move these methods here, because vm threads get into ObjectSynchronizer::enter
529 // However, there is a note in JavaThread::is_lock_owned() about the VM threads not being
530 // used for compilation in the future. If that change is made, the need for these methods
531 // should be revisited, and they should be removed if possible.
532 
533 bool Thread::is_lock_owned(address adr) const {
534   assert(LockingMode != LM_LIGHTWEIGHT, "should not be called with new lightweight locking");
535   return is_in_full_stack(adr);
536 }
537 
538 bool Thread::set_as_starting_thread() {
539   assert(_starting_thread == nullptr, "already initialized: "
540          "_starting_thread=" INTPTR_FORMAT, p2i(_starting_thread));
541   // NOTE: this must be called inside the main thread.
542   DEBUG_ONLY(_starting_thread = this;)
543   return os::create_main_thread(JavaThread::cast(this));
544 }
545 
546 // Ad-hoc mutual exclusion primitives: SpinLock
547 //
548 // We employ SpinLocks _only for low-contention, fixed-length
549 // short-duration critical sections where we're concerned
550 // about native mutex_t or HotSpot Mutex:: latency.
551 //
552 // TODO-FIXME: ListLock should be of type SpinLock.
553 // We should make this a 1st-class type, integrated into the lock
554 // hierarchy as leaf-locks.  Critically, the SpinLock structure
555 // should have sufficient padding to avoid false-sharing and excessive
556 // cache-coherency traffic.
557 
558 
559 typedef volatile int SpinLockT;
560 
561 void Thread::SpinAcquire(volatile int * adr, const char * LockName) {
562   if (Atomic::cmpxchg(adr, 0, 1) == 0) {
563     return;   // normal fast-path return
564   }
565 
566   // Slow-path : We've encountered contention -- Spin/Yield/Block strategy.
567   int ctr = 0;
568   int Yields = 0;
569   for (;;) {
570     while (*adr != 0) {
571       ++ctr;
572       if ((ctr & 0xFFF) == 0 || !os::is_MP()) {
573         if (Yields > 5) {
574           os::naked_short_sleep(1);
575         } else {
576           os::naked_yield();
577           ++Yields;
578         }
579       } else {
580         SpinPause();
581       }
582     }
583     if (Atomic::cmpxchg(adr, 0, 1) == 0) return;
584   }
585 }
586 
587 void Thread::SpinRelease(volatile int * adr) {
588   assert(*adr != 0, "invariant");
589   OrderAccess::fence();      // guarantee at least release consistency.
590   // Roach-motel semantics.
591   // It's safe if subsequent LDs and STs float "up" into the critical section,
592   // but prior LDs and STs within the critical section can't be allowed
593   // to reorder or float past the ST that releases the lock.
594   // Loads and stores in the critical section - which appear in program
595   // order before the store that releases the lock - must also appear
596   // before the store that releases the lock in memory visibility order.
597   // Conceptually we need a #loadstore|#storestore "release" MEMBAR before
598   // the ST of 0 into the lock-word which releases the lock, so fence
599   // more than covers this on all platforms.
600   *adr = 0;
601 }