diff -r e4fd2000638f core/CodegenLIR.cpp
--- a/core/CodegenLIR.cpp	Mon Jul 27 14:11:41 2009 +0800
+++ b/core/CodegenLIR.cpp	Tue Jul 28 08:46:22 2009 +0200
@@ -46,6 +46,10 @@
 #include "CodegenLIR.h"
 #include "../core/FrameState.h"
 
+#ifdef ENABLE_PROFILE_ARM
+#include "../nanojit/ARMProfiler.h"
+#endif
+
 #if defined(WIN32) && defined(AVMPLUS_ARM)
 #include <cmnintrin.h>
 #endif
@@ -1315,6 +1319,16 @@
 
         emitStart(gc, lirbuf, lirout);
 
+        #ifdef ENABLE_PROFILE_ARM
+        Stringp methodName = info->getMethodName();
+        StUTF8String utf8MethodName(methodName);
+        char* name = (char*)malloc(utf8MethodName.length() + 1);
+        memcpy(name, utf8MethodName.c_str(), utf8MethodName.length() + 1);
+        int32_t funcIndex = ARMProfiler::addProfileEvent(name, NULL);
+        Ins(LIR_line, InsConst((funcIndex << 1) | 1));
+        ARMProfiler::autoFreeMemory(name);
+        #endif
+
         if (overflow)
             return false;
 
@@ -3341,6 +3355,11 @@
                         retvalue = atomToNativeRep(t, retvalue);
                     }
                 }
+
+                #ifdef ENABLE_PROFILE_ARM
+                Ins(LIR_line, InsConst((ARMProfiler::StopSampling << 1) | 0));
+                #endif
+
                 switch (bt(t)) {
                 case BUILTIN_number:
                     Ins(LIR_fret, retvalue);
diff -r e4fd2000638f nanojit/Assembler.cpp
--- a/nanojit/Assembler.cpp	Mon Jul 27 14:11:41 2009 +0800
+++ b/nanojit/Assembler.cpp	Tue Jul 28 08:46:22 2009 +0200
@@ -1457,6 +1457,14 @@
                     break;
                 }
                 #endif // VTUNE
+
+                #ifdef ENABLE_PROFILE_ARM
+                case LIR_line:
+                {
+                    asm_profile((uint32_t) ins->oprnd1()->imm32());
+                    break;
+                }
+                #endif
             }
 
             if (error())
diff -r e4fd2000638f nanojit/Assembler.h
--- a/nanojit/Assembler.h	Mon Jul 27 14:11:41 2009 +0800
+++ b/nanojit/Assembler.h	Tue Jul 28 08:46:22 2009 +0200
@@ -298,6 +298,9 @@
             Register    asm_binop_rhs_reg(LInsp ins);
             NIns*       asm_branch(bool branchOnFalse, LInsp cond, NIns* targ);
             void        asm_switch(LIns* ins, NIns* target);
+            #ifdef ENABLE_PROFILE_ARM
+            void        asm_profile(uint32_t);
+            #endif
             void        assignSavedRegs();
             void        reserveSavedRegs();
             void        assignParamRegs();
diff -r e4fd2000638f nanojit/LIR.h
--- a/nanojit/LIR.h	Mon Jul 27 14:11:41 2009 +0800
+++ b/nanojit/LIR.h	Tue Jul 28 08:46:22 2009 +0200
@@ -775,6 +775,9 @@
                    (isCall() && !isCse()) ||
                    isStore() ||
                    isop(LIR_loop) || isop(LIR_label) || isop(LIR_live) ||
+#ifdef ENABLE_PROFILE_ARM
+                   isop(LIR_line) ||
+#endif
                    isRet();
         }
 
diff -r e4fd2000638f nanojit/NativeARM.cpp
--- a/nanojit/NativeARM.cpp	Mon Jul 27 14:11:41 2009 +0800
+++ b/nanojit/NativeARM.cpp	Tue Jul 28 08:46:22 2009 +0200
@@ -40,6 +40,10 @@
 
 #include "nanojit.h"
 
+#ifdef ENABLE_PROFILE_ARM
+#include "ARMProfiler.h"
+#endif
+
 #ifdef AVMPLUS_PORTING_API
 #include "portapi_nanojit.h"
 #endif
@@ -2020,5 +2024,21 @@
     NanoAssert(0);
 }
 
+#ifdef ENABLE_PROFILE_ARM
+void
+Assembler::asm_profile(uint32_t index)
+{
+    underrunProtect(28);
+    // In a reversed order
+    *(--_nIns) = 0xe8bd500f;
+    IMM32((index & 0x1) ? &ARMProfiler::startSampling : &ARMProfiler::endSampling);
+    IMM32(index >> 1);
+    *(--_nIns) = 0xe59ff000;
+    *(--_nIns) = 0xe28fe008;
+    *(--_nIns) = 0xe59f0004;
+    *(--_nIns) = 0xe92d500f;
+}
+#endif
+
 }
 #endif /* FEATURE_NANOJIT */
diff -r e4fd2000638f nanojit/manifest.mk
--- a/nanojit/manifest.mk	Mon Jul 27 14:11:41 2009 +0800
+++ b/nanojit/manifest.mk	Tue Jul 28 08:46:22 2009 +0200
@@ -55,6 +55,8 @@
 
 ifeq (arm,$(TARGET_CPU))
 nanojit_cpu_cxxsrc := NativeARM.cpp
+avmplus_CXXSRCS := $(avmplus_CXXSRCS) \
+  $(curdir)/ARMProfiler.cpp
 endif
 
 ifeq (sparc,$(TARGET_CPU))
diff -r e4fd2000638f shell/avmshell.cpp
--- a/shell/avmshell.cpp	Mon Jul 27 14:11:41 2009 +0800
+++ b/shell/avmshell.cpp	Tue Jul 28 08:46:22 2009 +0200
@@ -37,6 +37,10 @@
 
 #include "avmshell.h"
 
+#ifdef ENABLE_PROFILE_ARM
+#include "../nanojit/ARMProfiler.h"
+#endif
+
 namespace avmshell
 {
 #ifdef AVMPLUS_WIN32
@@ -121,6 +125,9 @@
 #endif /* AVMPLUS_WITH_JNI */
 		
 		MMgc::GCHeap::Destroy();
+#ifdef ENABLE_PROFILE_ARM
+		ARMProfiler::printProfile(stdout);
+#endif
 	 	return 0;
 	}
 

