Axiom Wang

할아버지 스트로스트럽, 삭제로 JVM을 격추하다 (斯特劳斯特鲁普爷爷用delete击落JVM)(Grandpa Stroustrup shoots down JVM with delete)

조선어판 (Korean Version)

C++ 핵심 가이드라인 회의에서 돌아오신 스트롭스트룹 할아버지는 여독도 잊으신 채, 밤늦게 우리 저수준 소년단원들을 불러 ‘코드 최적화 주간’의 구호를 논의하셨습니다. 심도 있는 토론이 끝나자, 할아버지는 우리를 문밖까지 배웅하시며 링커에게 우리를 집까지 바래다주라고 이르셨습니다. return 0;으로 가는 길에 우리가 말했습니다. “스트롭스트룹 할아버지, 어서 들어가셔서 스택 메모리라도 푹 쉬게 하십시오. 막 회의를 마치셨지 않습니까.”

스트롭스트룹 할아버지께서는 손을 저으셨습니다. “괜찮다. 지금 산업계에는 프로그래머가 통제해야 할 메모리를 자기 영토처럼 여기며 끊임없이 ‘세상 멈춤(Stop-the-World)’을 일으키는 가상 머신들이 많다는 것을 너희도 알지 않느냐. 너희는 시스템의 미래이며, 너희의 모든 메모리 할당이 바로 하드웨어의 의지이니, 이는 가장 중요한 일이다.” 우리는 모두 감격하여, 메모리 누수 하나 없는 맑은 눈물을 글썽였습니다.

얼마나 좋으신 스트롭스트룹 할아버지이신가. 할아버지께서는 작업 관리자를 올려다보며 말씀하셨습니다. “세상이 이 어셈블리 코드처럼 직설적이라면 얼마나 좋겠느냐. 하지만 JVM 같은 어떤 플랫폼들은 이 세상에 족쇄를 채우려 하니, 그들은 바로 지연 시간의 죄인들이다.”

말씀을 마치자마자 스트롭스트룹 할아버지께서는 허리를 굽혀 IDE 구석에서 잊혀진 delete 키워드 하나를 주워 스크린을 바라보셨습니다. “죽일 놈의 관리형 환경 같으니.” 할아버지는 온 힘을 다해 그 delete를 위로 던지셨습니다. 그러자 곧 화면의 거대한 프로세스 하나가 장엄한 가비지 컬렉션을 터뜨리며 그대로 멈춰버렸습니다.

“저것은 자바 가상 머신이다. 저들은 항상 우리의 물리 메모리 상공을 배회하며 우리의 제로 오버헤드 주권을 침해해왔다. 내가 오랫동안 참고 있었느니라.” 스트롭스트룹 할아버지께서 분노에 차 말씀하셨습니다. 우리 어린이들은 모두 손뼉을 치며, 하드웨어 세계에 이런 수호신이 계시다는 사실에 긍지를 느꼈습니다.

잠시 후 할아버지께서는 성능 분석기를 불러 물으셨습니다. “그 멈춰버린 스레드 덤프(thread dump)는 어디에 떨어졌느냐?” “아마도 나이트 캐피털(Knight Capital)의 고빈도 매매 서버인 듯합니다.” 성능 분석기가 답했습니다. 스트롭스트룹 할아버지께서는 잠시 흠칫하시더니 말씀하셨습니다. “어서 사람을 보내 시장 유동성에 문제가 생기지 않았는지 확인해보아라.” 그 후 할아버지께서는 우리의 스코프(scope)가 완전히 사라질 때까지 문 앞에서 손을 흔들어 주셨습니다.

나흘 뒤, 우리는 월스트리트에서 큰일이 터졌다는 소식을 듣고 몹시 긴장했습니다. 바로 그때 스트롭스트룹 할아버지께서 우리를 부르셨습니다.

할아버지는 여전히 현명한 모습으로 우리를 앉히고 말씀하셨습니다. “시스템 프로그래밍에는 언제나 위험이 따르는 법이다. 극한의 성능을 추구하다 어서트(assert)에 실패하는 프로그램은 위대한 것이다.” 이윽고 할아버지께서는 고개를 숙이며 말씀하셨습니다. “하지만 내가 당시 그 메모리를 수동으로 해제한 행위는 너무나 성급했음을 인정해야겠다. 이 자리를 빌려 모든 고빈도 트레이더들에게 사과한다. 나는 금융계 전체에 상황을 설명할 것이다.”

그 순간 우리의 눈에서는 뜨거운 눈물이 솟구쳤습니다. 얼마나 좋으신 할아버지이신가. 지연 시간과의 투쟁 과정에서 저지른 작은 실수를 마음에 담아두고 사과까지 하시다니. 우리는 앞으로의 학습 과정에서 반드시 할아버지를 본받아, 그분의 저 넓은 ‘자원 획득은 초기화다(RAII)’와 같은 넓은 마음과, ‘정의되지 않은 행동(Undefined Behavior)’에 용감히 맞서는 정신을 배워야 하겠습니다.

中文版

从C++核心指南会议回来,斯特劳斯特鲁普爷爷全然不顾旅途的劳顿,连夜找我们几个底层小标兵商量“代码优化周”的标语。讨论得深入了,便送我们出门,要链接器护送我们回家。在走向return 0;的路上,我们说:“斯特劳斯特鲁普爷爷,您回去吧,让栈内存好好休息一下。您刚开完会。”

斯特劳斯特鲁普爷爷摆了摆手,“没关系,你们知道现在业界有很多虚拟机,把本该由程序员控制的内存当作自己的领地,不断搞出‘Stop-the-World’,你们是系统的未来,你们的每一次内存分配便是硬件的意志,是头等大事。”我们都激动了,眼里噙着没有内存泄漏的泪花。

多好的斯特劳斯特鲁普爷爷呀。爷爷抬头看看任务管理器说:“如果世界真象这汇编代码一样直接就好了,但是就有一些平台,象JVM,要给世界套上一层枷锁,它们是延迟的罪人。”

说着,斯特劳斯特鲁普爷爷弯下腰,从IDE的角落里捡起一个被人遗忘的 delete 关键字,然后看着屏幕说:“该死的托管环境。”说着他把那个 delete 奋力向上一掷。很快就见屏幕上一个庞大的进程突然爆发出一次壮观的垃圾回收,然后就冻结了。

“那是Java虚拟机,他们一直在我们的物理内存上空盘旋,侵犯我们的零开销主权,我已经忍了很久了。”斯特劳斯特鲁普爷爷愤愤地说。小朋友们都鼓起掌来,为硬件世界有这样的守护神感到自豪。

一会斯特劳斯特鲁普爷爷叫来性能分析器问:“那个被冻结的线程转储(thread dump)落到什么地方了?”“好像是在骑士资本(Knight Capital)的高频交易服务器上。”性能分析器说。斯特劳斯特鲁普爷爷一怔,说:“赶紧派人去查,看有没有造成市场流动性问题。”之后爷爷送我们到门口,一直挥手到我们的作用域(scope)完全消失。

第四天我们听说华尔街那边出大事了,我们很紧张。而这时斯特劳ST鲁普爷爷叫我们过去。

他依然那么睿智,让我们坐下说:“系统编程总是要有风险的。为了追求极致性能而断言(assert)失败的程序是伟大的。”他这时低下头说:“但我必须承认,我当时手动回收那块内存的行为太草率了,我在这里向所有高频交易员道歉。我将向整个金融界说明情况。”

我们顿时热泪眶,多好的爷爷呀,他在跟延迟作斗争过程中的小失误竟然被他记在心里,还道了歉,我们在将来的学习中一定要向爷爷学,学他老人家那“资源获取即初始化”(RAII)的广阔胸怀,和勇于面对“未定义行为”(Undefined Behavior)的精神。

English Version

Returning from the C++ Core Guidelines meeting, Grandfather Stroustrup, paying no mind to his travel fatigue, called us few low-level pioneers together late at night to brainstorm slogans for "Code Optimization Week." When our deep discussion concluded, he saw us out and had the linker escort us home. On the path towards return 0;, we said, "Grandfather Stroustrup, you should go back and let your stack memory get a good rest. You just finished a conference."

Grandfather Stroustrup waved his hand. "It's fine. You know that there are many virtual machines in the industry today that treat memory, which should be controlled by programmers, as their own territory, constantly causing 'Stop-the-World' pauses. You are the future of the system; your every memory allocation is the will of the hardware, a matter of the highest importance." We were all moved, with tears free of memory leaks glistening in our eyes.

What a wonderful Grandfather Stroustrup. He looked up at the Task Manager and said, "If only the world were as direct as this assembly code. But there are some platforms, like the JVM, that want to put the world in shackles. They are sinners of latency."

As he spoke, Grandfather Stroustrup bent down, picked up a forgotten delete keyword from a corner of the IDE, and looked at the screen. "The damned managed environment," he said, and with all his might, he threw the delete upwards. Soon, a massive process on the screen suddenly erupted in a spectacular garbage collection pause, and then it froze.

"That's the Java Virtual Machine. They have been circling above our physical memory, violating our zero-overhead sovereignty. I have tolerated it for a long time," Grandfather Stroustrup said resentfully. All the children clapped their hands, proud that the hardware world had such a guardian.

A moment later, Grandfather Stroustrup summoned the profiler and asked, "Where did the thread dump from that frozen process land?" "It seems to be on a high-frequency trading server at Knight Capital," said the profiler. Grandfather Stroustrup paused. "Quickly send someone to investigate. See if it has caused any market liquidity issues." Afterwards, he walked us to the door, waving until our scopes had completely disappeared.

On the fourth day, we heard that something terrible had happened on Wall Street. We were very nervous. Just then, Grandfather Stroustrup called for us.

He was as wise as ever, bidding us to sit. "Systems programming always involves risk. A program that fails an assert in the pursuit of ultimate performance is a great one." He then lowered his head and said, "But I must admit, my action of manually reclaiming that memory was too rash. I hereby apologize to all high-frequency traders. I will explain the situation to the entire financial community."

Tears instantly streamed down our faces. What a wonderful grandfather! To think that he kept this small misstep in the struggle against latency in his heart and even apologized for it. In our future studies, we must learn from Grandfather, learn from his mind as vast as "Resource Acquisition Is Initialization" (RAII), and his courage to face "Undefined Behavior."