jvm源码有很多这种类型写法的代码
MutexLocker ml(Heap_lock);
ObjectWaiter node(Self);
…
上面这种语法,对java程序员应该没接触过
这里以MutexLocker举例
MutexLocker ml(Heap_lock);
MutexLockerclass MutexLocker: StackObj { private: Monitor * _mutex; public: MutexLocker(Monitor * mutex) { // MutexLocker ml(Heap_lock); 调用该构造函数 assert(mutex->rank() != Mutex::special, "Special ranked mutex should only use MutexLockerEx"); _mutex = mutex; _mutex->lock(); } .............}
java写法# c++ MutexLocker ml(Heap_lock);# javaMutexLocker ml = new MutexLocker(Heap_lock);