账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    jvm8 hotspot源码c++语法问题
    35
    0
    void Parker::park(bool isAbsolute, jlong time) {
      // Optional fast-path check:
      // Return immediately if a permit is available.
      if (_counter > 0) {
          _counter = 0 ;
          OrderAccess::fence();
          return ;
      }
    
      Thread* thread = Thread::current();
      assert(thread->is_Java_thread(), "Must be JavaThread");
      JavaThread *jt = (JavaThread *)thread;
    
      // Optional optimization -- avoid state transitions if there's an interrupt pending.
      // Check interrupt before trying to wait
      if (Thread::is_interrupted(thread, false)) {
        return;
      }
    
      // Next, demultiplex/decode time arguments
      timespec absTime;
      if (time < 0 || (isAbsolute && time == 0) ) { // don't wait at all
        return;
      }
      if (time > 0) {
        unpackTime(&absTime, isAbsolute, time);
      }
    
    
      // Enter safepoint region
      // Beware of deadlocks such as 6317397.
      // The per-thread Parker:: mutex is a classic leaf-lock.
      // In particular a thread must never block on the Threads_lock while
      // holding the Parker:: mutex.  If safepoints are pending both the
      // the ThreadBlockInVM() CTOR and DTOR may grab Threads_lock.
      ThreadBlockInVM tbivm(jt);
    
      // Don't wait if cannot get lock since interference arises from
      // unblocking.  Also. check interrupt before trying wait
      if (Thread::is_interrupted(thread, false) || pthread_mutex_trylock(_mutex) != 0) {
        return;
      }
    
      int status ;
      if (_counter > 0)  { // no wait needed
        _counter = 0;
        status = pthread_mutex_unlock(_mutex);
        assert (status == 0, "invariant") ;
        OrderAccess::fence();
        return;
      }
    
    #ifdef ASSERT
      // Don't catch signals while blocked; let the running threads have the signals.
      // (This allows a debugger to break into the running thread.)
      sigset_t oldsigs;
      sigset_t* allowdebug_blocked = os::Linux::allowdebug_blocked_signals();
      pthread_sigmask(SIG_BLOCK, allowdebug_blocked, &oldsigs);
    #endif
    
      OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
      jt->set_suspend_equivalent();
      // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
    
      if (time == 0) {
        status = pthread_cond_wait (_cond, _mutex) ;
      } else {
        status = os::Linux::safe_cond_timedwait (_cond, _mutex, &absTime) ;
        if (status != 0 && WorkAroundNPTLTimedWaitHang) {
          pthread_cond_destroy (_cond) ;
          pthread_cond_init    (_cond, NULL);
        }
      }
      assert_status(status == 0 || status == EINTR ||
                    status == ETIME || status == ETIMEDOUT,
                    status, "cond_timedwait");
    
    #ifdef ASSERT
      pthread_sigmask(SIG_SETMASK, &oldsigs, NULL);
    #endif
    
      _counter = 0 ;
      status = pthread_mutex_unlock(_mutex) ;
      assert_status(status == 0, status, "invariant") ;
      // If externally suspended while waiting, re-suspend
      if (jt->handle_special_suspend_equivalent_condition()) {
        jt->java_suspend_self();
      }
    
      OrderAccess::fence();
    }

    上面的代码是jvm实现LockSupport.park()的功能,
    status = os::Linux::safe_cond_timedwait (_cond, _mutex, &absTime) ;
    这里用了2次::,看不太明白,首先我没有看到os的类定义在哪,其次没有看到os里面有linux的定义。看过这个源码的大牛能否告知下?### 问题描述

    问题出现的环境背景及自己尝试过哪些方法

    相关代码

    // 请把代码文本粘贴到下方(请勿用图片代替代码)

    你期待的结果是什么?实际看到的错误信息又是什么?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 共 0 条
    • 青峰道士 普通会员 1楼

      JVM Hotspot,由Sun Microsystems开发并维护,是Java虚拟机的最新版本。在Hotspot中,C++是被编译为Java字节码的。如果你在Java源代码中遇到关于Hotspot编译的问题,可能需要检查以下几点:

      1. C++编译:你需要确保你的C++代码已经被正确编译。如果你使用的是GCC,你需要在编译时添加相应的C++选项。例如,如果你使用GCC编译器,你可以添加 -O3 或 -g 选项,以获得更高质量的输出。

      2. C++语法:如果你在Hotspot中遇到了C++语法问题,你需要检查你的代码。例如,如果你使用了C++11特性,你需要确保你的代码符合C++11的语法。

      3. Java字节码:如果你在Java代码中遇到了关于Hotspot编译的问题,你需要检查你的Java字节码。如果你使用的是JDK,你需要确保你的Java字节码已经被正确编译。你可以使用javac命令来编译你的Java字节码。

      4. 兼容性问题:在Hotspot中,Java和C++是不同的语言,可能需要进行一些兼容性处理。例如,如果你在Java代码中使用了C++特性,你需要确保你的代码可以被Hotspot正确处理。

      如果你仍然无法解决问题,你可能需要寻求专业的帮助,例如向Sun Microsystems或者你的开发者团队寻求支持。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部