Observability of the Java Virtual Machine

Image
The JVM is one of the most observable runtimes. It provides us lots of tools for troubleshooting a JVM application in production. 1. Thread observability Threads are how the JVM actually does work. When something is wrong in production, the symptom is almost always a thread: stopped, blocked, leaking etc. Thread dumps work on any JVM with no  instrumentation, no agents, no restarts. <Example project link with /threaddump endpoint>         // (1) Deadlock — two threads grab the same pair of locks in opposite order.         new Thread(() -> grab(LOCK_A, LOCK_B), "deadlock-A-then-B").start();         new Thread(() -> grab(LOCK_B, LOCK_A), "deadlock-B-then-A").start(); http://localhost:8080/actuator/threaddump To list the JVMS, we can use the command below. PS C:\observe-jvm> jps -lv 25296 jdk.jcmd/sun.tools.jps.Jps -Dapplication.home=C:\Program Files\Microsoft\jdk-21.0.3.9-hotspot -Xms8m -Djdk.module.main=...

"Parsing" Konusu ile ilgili Temel Kavramlar

--Halen yazım aşamasında--

Regular expressions yardımıyla bir programın "lexical" yapısını ifade edebildiğimizi görmüştük. Aynı şeyi dildeki cümleler için yapmak mümkün mü?
Dildeki cümlelerin yapısını ifade etmek için "context free grammar" kavramı kullanılmakta.
Dildeki karmaşık yapıları oluşturmak için "production" yaparak ilerlemek gerekiyor. Aşağıda 5 tane production ile ifade edilen bir dili inceleyelim:


S -> S ; S
S -> ID = E
E -> E + E
E -> ID
E -> NUM


Bu kuralları kullanarak bir cümle üretmeye çalışalım:


S ; S
ID = E ; ID = E
ID = E + E; ID = E
ID = ID + NUM; ID = NUM


Burada ürettiğimiz cümlenin kaynak kodu (lexer ele almadan önce) şöyle olabilirdi:


var = i + 4; j = 5


Burada tokenlerin değerleri: var, i, j, 4, 5
Token türleri: ID, NUM, "+", ";", "="

Gramer ifadesinde sağ tarafta bulunamayan sonlanmış semboller dikkati çekiyor. Bunlara "terminal symbol" deniliyor. Terminal semboller, token türlerine karşılık gelmekte: ID, NUM
Gramer ifadesinde sol tarafta bulunan semboller ise üretim yapmaya olanak veriyor. Bunlara "nonterminal symbol" deniliyor. Nonterminal sembollerden birisiyle üretim yapmaya başlıyoruz ki bu sembole start symbol deniliyor.

Ambiguous Grammar


E -> E - E
E -> id
Bu gramer ile ilgili örnek bir cümle:

3 – 2 – 5

id - id - id


Bu cümleyi 2 farklı ağaç yapısı şeklinde gösterebiliyoruz:

E
|-----------------|
id +
|------------------|
id id

veya

E
|------------------|
+ id
|------------------|
id id


İşte bu şekilde birden fazla ağaç yapısı ile temsil edilebilen gramerlere çok anlamlı (ambiguous) deniliyor. Aynı ifade farklı anlamlara gelen ağaç yapılarıyla temsil edilebildiği için bu gramerler yorumlama açısından sorun yaratıyor.
Çok anlamlılığı ortadan kaldırmak için grameri değiştirmemiz gerekiyor:

E -> E – T
T-> (E)
E -> id

Bir sonraki yazıda, tasarladığımız bir dil için nasıl parser oluşturacağımız üzerinde duralım.

Comments

Popular posts from this blog

The WeakReference class, monitoring memory leak and garbage collection in a Java application

Simplescalar Simulator - Part 2: sim-outorder.c

Notes on Java Performance