Tüm uzmanlıklarTeknoloji · İş görüşmesi

JVM

JVM soruları, Java kodunuzun altında neyin çalıştığını bilip bilmediğinizi gösterir. Garbage collection ve belleği sade İngilizceyle anlatmak, çalışarak geliştirilebilecek bir beceridir.

Kelimeler → ifadeler → cümleler → konuşma

SpeakRole’i dene ↗
İş görüşmesiJVM
V

What happens when the JVM runs out of heap memory?

0:18
Mülakat sorusu

JVM

Java pozisyonlarında mülakatçılar çoğu zaman dilden çalışma ortamına (runtime) geçer: bellek nasıl düzenlenir, nesneler nasıl temizlenir ve canlıdaki bir servisin belleği tükendiğinde ne yaparsınız. Orta düzey bir adayın bile ana fikirleri ve doğru araçları bilmesi beklenir.

Cevapları şu sırayla verin: ilgili parçanın ne yaptığı, basitçe nasıl çalıştığı ve gerçek bir sistemde, örneğin bir GC logunda ya da heap dump'ta bunu nasıl görürsünüz. Sürüme özgü ayrıntılarda dikkatli olun; emin değilseniz "in modern Java" ya da "it depends on the version" deyin.

  • ✓Kelimeler → ifadeler → cümleler → konuşma
  • ✓Yanıtın anlamı
  • ✓Dil

Sık sorulan mülakat soruları ve örnek cevaplar

How does garbage collection work in the JVM?

JVM'de garbage collection nasıl çalışır?

Mülakatçı ne duymak ister. Köklerden erişilebilirlik (reachability), nesil (generation) fikri, kısa ve uzun duraklamalar arasındaki fark ve adı geçen en az bir collector.

Yüksek sesle çalışmak için İngilizce örnek cevap

The JVM frees the memory of objects that can no longer be reached from the roots, such as thread stacks and static fields. Most objects die young, so the heap is usually divided into a young generation and an old generation. New objects go to the young area, and a small, fast collection cleans it. Objects that survive move to the old area, which is collected less often. Some phases stop the application, and we call that a stop-the-world pause. In modern Java, G1 is usually the default collector, and it tries to keep pauses short. ZGC and Shenandoah aim for even shorter pauses. I choose by the pause and throughput requirements, and I check the GC logs.

What are the main memory areas of the JVM?

JVM'in başlıca bellek alanları nelerdir?

Mülakatçı ne duymak ister. Heap, thread stack'leri, metaspace ve native bellek; hangisinde ne tutulduğu. Ek puan: hangi hatanın hangi alana işaret ettiği.

Yüksek sesle çalışmak için İngilizce örnek cevap

The biggest area is the heap, where objects are created and where the garbage collector works. Each thread has its own stack, which holds method frames with local variables and references. When the stack gets too deep, for example with endless recursion, we get a StackOverflowError. Class metadata is stored in metaspace, which uses native memory and replaced the old permanent generation in Java 8. There is also memory outside the heap: thread stacks, direct buffers and the code cache with compiled code. This is important in containers, because the process uses more memory than the heap size alone.

How does class loading work in the JVM?

JVM'de class loading nasıl çalışır?

Mülakatçı ne duymak ister. Yükleme, bağlama (linking) ve başlatma (initialisation), üst yükleyiciye devretme (parent delegation) modeli ve ClassNotFoundException ile NoClassDefFoundError arasındaki fark.

Yüksek sesle çalışmak için İngilizce örnek cevap

The JVM loads classes lazily, when they are first needed. A class loader finds the bytecode and creates the class. Then the class is linked, which means it is verified and prepared, and finally it is initialised: static fields are set and static blocks run. Class loaders form a hierarchy with parent delegation. A loader first asks its parent to load the class, and only then tries by itself. This protects core classes like String from being replaced. ClassNotFoundException happens when code asks for a class by name and it is not found. NoClassDefFoundError usually means that the class existed at compile time but is missing at runtime, or that its static initialisation failed.

How do you investigate a memory leak or an OutOfMemoryError?

Bir bellek sızıntısını ya da OutOfMemoryError'ı nasıl incelersiniz?

Mülakatçı ne duymak ister. Uygulamalı bir sıra: GC logları ve metriklerle doğrula, heap dump al, analiz et, referans zincirini bul ve nedeni düzelt.

Yüksek sesle çalışmak için İngilizce örnek cevap

First I check whether it is really a leak. In the GC logs or the metrics, I look at whether the memory after a full collection keeps growing. I make sure the JVM writes a heap dump on OutOfMemoryError, or I take one with jcmd. Then I open it in a tool like Eclipse Memory Analyzer and look for the biggest objects and the path from a GC root that keeps them alive. Typical causes are static collections that only grow, caches without a size limit, listeners that are never removed and ThreadLocal values in long-living threads. After the fix, I watch the memory again under similar load.

How do you tune a JVM for a production service?

Canlıdaki bir servis için JVM'i nasıl ayarlarsınız (tuning)?

Mülakatçı ne duymak ister. Önce ölç; heap boyutu, collector seçimi, container sınırları ve ısınma (warm-up); net bir hedefle her seferinde tek değişiklik.

Yüksek sesle çalışmak için İngilizce örnek cevap

I start with a goal: low latency, high throughput or small memory use. Then I measure, and I never tune by guessing. I enable GC logging, set the maximum heap with Xmx, and often set the initial heap to the same size to avoid resizing. In a container, I leave room for non-heap memory, so I set the heap as a percentage of the container limit, for example with MaxRAMPercentage. I change one parameter at a time and test under realistic load. I also remember that the JIT compiler needs warm-up, so the first minutes after a start are slower, and a load test must run long enough to show the real picture.

Anahtar terimler nasıl telaffuz edilir

JVM
cey-vi-em
heap
hiip (uzun “ii”; “hip” değil)
metaspace
MET-ı-speys
bytecode
BAYT-kod
JIT
cit (“bit” ile uyaklı) ya da cey-ay-ti
allocation
a-lı-KEY-şın
generation
ce-nı-REY-şın

Cevap vermek için kullanışlı kalıplar

  • Under the hood, the JVM…Arka planda JVM…
  • The GC logs show that…GC logları şunu gösteriyor:…
  • I would take a heap dump and look at…Bir heap dump alır ve şuna bakardım:…
  • The trade-off is between pause time and throughput.Buradaki ödünleşim (trade-off), duraklama süresi ile throughput arasında.
  • It depends on the JVM version and the collector.Bu, JVM sürümüne ve collector'a bağlı.
  • The object stays reachable because…Nesne, şu nedenle erişilebilir kalıyor:…
  • I would measure under realistic load first.Önce gerçekçi yük altında ölçerdim.

Sık yapılan hatalar

  • Java bellek modelini JVM bellek alanlarıyla karıştırmak. İlki thread'ler arasındaki görünürlükle, ikincisi heap, stack ve metaspace ile ilgilidir. Hangisini kastettiğinizi söyleyin.
  • “Garbage collector kullanılmayan nesneleri siler” deyip durmak. Köklerden erişilebilirliği ve nesil fikrini açıklayın. En sık görülen zayıf nokta budur.
  • Bellek sızıntısının çözümü olarak daha büyük bir heap önermek. Daha büyük heap, çöküşü yalnızca erteler. Nesneleri canlı tutan referansı bulduğunuzu söyleyin.
  • Parametreleri sürümü söylemeden ezberden sıralamak. Birçok seçenek Java sürümleri arasında değişti; "in recent versions" deyin ve dokümantasyonu kontrol edin.
  • "heap" sözcüğünü Türkçedeki “hip” gibi kısa okumak. Ünlü uzundur, "cheap" sözcüğündeki gibi. Anahtar sözcükleri yüksek sesle çalışın; yanlış bir ünlü, kastettiğiniz sözcüğü değiştirebilir.

Sıkça sorulan sorular

GC algoritmalarını ayrıntılı bilmem gerekir mi?

Ana fikirler gerekir: erişilebilirlik, nesiller, duraklamalar ve hedefleriyle birlikte bir iki collector. Bölge (region) boyutları ya da ayar bayrakları gibi ayrıntılar yalnızca kıdemli ya da performans odaklı pozisyonlarda beklenir.

Hangi JVM araçlarından söz etmeliyim?

Kullandıklarınızı söyleyin: GC logları, jcmd, thread dump için jstack, Java Flight Recorder ve Eclipse Memory Analyzer gibi bir heap analiz aracı. Yalnızca bir izleme panosu kullandıysanız bunu söyleyin ve nelere baktığınızı açıklayın.

Java sürümünden söz etmeli miyim?

Evet. Son projenizde hangi sürümü kullandığınızı söyleyin ve bazı davranışların sürümler arasında farklı olduğunu belirtin. Bu, çalışma ortamının değiştiğini bildiğinizi gösterir ve yalnızca tek bir sürüm için doğru olan bir şeyi iddia etmekten sizi korur.

Bir cevabı okumak ile onu söylemek aynı şey değildir. Her soruyu yüksek sesle çalışın, ardından kendi cevabınızın anlamını ve dilini karşılaştırın.

SpeakRole’i dene ↗

Bu alandaki diğer konular