Posts

Java JVM high memory usage problems

Though I have some three four years experience in C++ ,I did not have that much oppurtunity to work in Java. Currenly I was doing some analysis for a very simple CLI and was surprised to come with a memory restriction. I found that if I use Java for developing the CLI application I will be exhausting the memory of our Application Server (AS). Just to mention the architecture ,users (telecom operators) use a metaframe server client ( =something like remote desktop) to login to the AS and then open a GUI to work on it. With Java I can service only about 15 clients with the available memory . I just checked the reason for this resource crunch and found that already many Java based GUI's are served by the AS and each is taking some 25 MB or more. The first thing I thought is that adding more RAM will solve this ( though this is not an easy option) . Then I understood that a 32 bit system can have just about 3 gb ram for applciations and our AS had already 4 GB with 1.5 GB VM also co...

Windebug and Adplus for debugging process hang

1. Set the symbol, especillay windows symbols .......26_Merged\UNCRelease;\\blrm2fsp\SCSD-Common\Sym\WinSym2K3SP1 2. Set the souce and image 3. Load the extension dll ( for !locks command ) if not already loaded .load C:\Program Files\Debugging Tools for Windows\winxp\kdexts.dll 4. Use the !ntsdexts.locks ( or !locks ) command to see a list of critical section :004> !ntsdexts.locks CritSec ntdll!LdrpLoaderLock +0 at 7C889D94 LockCount -6902 RecursionCount 1 OwningThread 2b3c EntryCount 0 ContentionCount 28f3 *** Locked CritSec +12f9b4 at 0012F9B4 LockCount 0 RecursionCount 0 OwningThread 0 *** Locked CritSec +12f70c at 0012F70C LockCount 0 RecursionCount 0 OwningThread 0 *** Locked CritSec +128202c at 0128202C LockCount -2 RecursionCount 1 OwningThread 3d9c EntryCount 0 ContentionCount 0 *** Locked ----------- A 'LockCount' other than 0 means that many threads are waitiing on t...

windbg command

Wednesday, 25 August 2004 To list all modules loaded by the process -LM (shows the loaded module address also) : WinDebug thread commands To see all threads ~ To freeze all threads ~*F to unfreeze thread 1 ~1U to set the thread ~S copying to stl list If destination is an empty list lstOfInt.push_back(1); lstOfInt.push_back(2); lstOfInt.push_back(3); copy(lstOfInt.begin(),lstOfInt.end(),lstOfIntDest.begin() ); -->WRONG copy(lstOfInt.begin(),lstOfInt.end(),back_inserter(lstOfIntDest) ); -->CORRECT

CORBA - C++ Client (ACE TAO) Java Server (JacORB) A simple example

Step 1 I downloaded the binary relaease of JacOrb Extracted the zip file to E:\Program Files\JacORB-2.2.4\ Step 2 Then also downloaded Ant Also jdk was downloaded and installed Step 3 Then created the batch file (to set the path) Set ANT_HOME=E:\Program Files\Java_Ant\apache-ant-1.6.5 Set JAVA_HOME=E:\Program Files\Java\jdk1.5.0_03 Set JACORB_HOME=E:\Program Files\JacORB-2.2.4 Set Path=%ANT_HOME%\bin;%JAVA_HOME%\bin;%JACORB_HOME%\bin;%JACORB_HOME%; Set CLASSPATH=%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib;%JAVA_HOME%;%JACORB_HOME%\lib; ----now to configure JacORB - In the command promt E:\Program Files\Java_Ant\apache-ant-1.6.5>ant jaco E:\Program Files\Java_Ant\apache-ant-1.6.5>ant idlcmd okay that’s done Now write the idl --- test1.idl------ module Quoter1 { //a test interface interface Stock { double price(); //to get the quote of the stock readonly attribute string symbol; readonly attribute string fullname; }; //interface to get the stock object exception InvalidStockSymbol {}; //to...

Importance of TypeSafety -An example

class Bank { private: bool bFirstLock; bool bSecondLock; BankVault* pBankVault; public: Bank() { bFirstLock=0; bSecondLock=0; pBankVault= new BankVault ; } bool IsLocked() { if(( true == bFirstLock) && (true== bSecondLock)) { printf("Both Locks unlocked- Bank is UNLOCKED\n"); return false; } else { printf("Bank is LOCKED\n"); return true; } }; }; //----------------------------------------------------- class Robber { short ForgedKey; void* pAceesor; public: Robber() { ForgedKey=0; }; RemoveLocks() { //This method has the instruction to set the first // 2 bytes (short) of the start of the class to value //257; This in binary is 00000001 00000001;ie the first 2 bytes to 1 ; //But since we are using the pointer of the Bank object to call //this method, it sets the first 2 bytes of the object of //bank to 00000001 00000001; But in the Bank object the first 2 //bytes are occupied by two boolean varia...

Unix - Checking the virtual memory of process

ps -elf | grep In Solaris the size (SIZ) column specifies memory size

customising stl find algorithm

customising stl find algorithm class tTaskType { public: int data; bool operator == (int k) { if(k ==data) return true; else return false; } }; --------------------------------- Main() tTaskType s1,s2,s3; s1.data =10; s2.data =12; s3.data =13; list test; list ::iterator Itrtest; test.push_back(s1); test.push_back(s2); test.push_back(s3); Itrtest =std::find(test.begin(),test.end() ,10) ; if(Itrtest!=test.end() ) { printf("Found\n"); }

Signalling event

Main thread { //Create an eventin the non signalled mode and wait for it HANDLE g_Event =CreateEvent(0,0,0,0); //this method will wait till the event is Signalled WaitForSingleObject(g_Event,INFINITE) ; } In another thread { //Set the event to signelled state, so that waitforsingle object can return SetEvent(g_Event) }

#define variable arguments

Since #define does not take variable arguments you have to work around using function pointers. void __format_out(const char* fmt, ...); typedef void (*ptr2Fn) (const char* fmt, ...) ; ptr2Fn _storeLine(int nSeverity,int lineNumber,char* fileName); #define CTRACE _storeLine(40,__LINE__,__FILE__) ----------------------- ptr2Fn _storeLine(int nPSeverity,int nPlineNumber,char* szPfileName) { nSeverity = nPSeverity; nlineNumber=nPlineNumber; szfileName = (char*)szPfileName; return __format_out; } ----------------------- inline void __format_out(const char * fmt, ...) { CString ___str; va_list marker; va_start(marker, fmt); USES_CONVERSION; ___str.FormatV(A2T(fmt), marker); va_end(marker); } TRACE("nUMBER IS %d",223);

vba code for iterating through colums

Private Sub CommandButton1_Click() CalculateAndDispalyDifference End Sub Sub CalculateAndDispalyDifference() Dim t1, t2 As Date For counter = 2 To 91 t1 = Worksheets("Sheet1").Cells(counter, 4).Value t2 = Worksheets("Sheet1").Cells(counter + 1, 4).Value If t2 > t1 Then Worksheets("Sheet1").Cells(counter, 6).Value = t2 - t1 Else Worksheets("Sheet1").Cells(counter, 6).Value = t1 - t2 End If counter = counter + 1 Next counter End Sub

VBA xode snippet for iterating through colums

Private Sub CommandButton1_Click() CalculateAndDispalyDifference End Sub Sub CalculateAndDispalyDifference() Dim t1, t2 As Date For counter = 2 To 91 t1 = Worksheets("Sheet1").Cells(counter, 2).Value //.Cells(row,column) t2 = Worksheets("Sheet1").Cells(counter, 4).Value If t2 > t1 Then Worksheets("Sheet1").Cells(counter, 5).Value = t2 - t1 Else Worksheets("Sheet1").Cells(counter, 5).Value = t1 - t2 End If Next counter End Sub

wcstok,strtok memory corruption

CString mystring("ob_jw_ay"); CString anotherstring ; anotherstring =mystring;//memory corruption!!! TCHAR* string = (TCHAR*)(LPCTSTR)mystring; TCHAR seps[] = "_"; TCHAR* token; token = strtok( string, seps ); while( token != NULL ) token = strtok( NULL, seps ); //Now both strings will be changed.Because both CString::m_pchData are pointing to the same memory and strok/wcstok changes it. If you want 'anotherstring' to remain unchanged do anotherstring + =mystring;

Structured Exception Handling

http://www.microsoft.com/msj/0197/Exception/Exception.aspx http://www.microsoft.com/msj/0898/bugslayer0898.aspx http://groups.google.co.in/groups?hl=en&lr=&ie=UTF-8&selm=Xns94A2C525A6E9EnospamJochenKalmbach%40207.46.248.16&rnum=2

vtable layout and lookup

struct cA ; struct A_vtbl { void (__stdcall* pfn_mem_fun)( struct cA* this, int v ) ; void (__stdcall* pfn_mem_fun2)( const struct cA* this ) ; void (__stdcall* pfn_mem_fun3)( struct cA* this ) ; void (__stdcall* pfn_destructor)( struct cA* this ) ; }; struct cA { struct A_vtbl* vptr ; char c1 ; int i ; char c2[1] ; }; void cfun( struct cA* pa ) { //pa->mem_fun2() ; pa->vptr->pfn_mem_fun2(pa) ; //pa->mem_fun(100) ; pa->vptr->pfn_mem_fun(pa,100); }

type safety importance link

From - http://www.securingjava.com/chapter-two/chapter-two-10.html Why Type Safety Matters Type safety is the most essential element of Java's security. To understand why, consider the following slightly contrived example. A calendar-management applet defines a class called Alarm. This class is represented in memory as shown in Figure 2.10. Alarm defines an operation turnOn, which sets the first field to true. The Java runtime library defines another class called Applet, whose memory layout is also shown in Figure 2.10. Note that the first field of Applet is fileAccessAllowed, which determines whether the applet is allowed access to files on the hard disk. Figure 2.10 Type safety provides an important foundation for the Java security model.In this figure, two classes, Alarm and Applet, each include a number of fields. Setting the first field in these classes to "true" is not equivalent. Type safety checks ensure that any object a method may try to manipulate is of ...

windbg commands

A good link for windbg commands ref http://perso.b2b2c.ca/makigor/files/WinDBG.rtf