java - Reloading classes with maniupulated bytecode from rt.jar -


i trying track method calls learning purposes.

the javagent have implemented modified version of implementation in this article. programm adds method call logging instructions bytecode. unfortunately bootstrap classloader refuses load manipulated content rt.jar. can understand isn't idea production enviroment, student amazing.

do got ideas how make happen?

i manipulate classes rt.jar.

for example manipulated bytecode of bigdecimal class. class training manipulate? , kind of manipulation doing? adding logs every method of class in article mentioned?

in additional of following instructions of article, had other things in order able manipulate classes of rt.jar.

  1. in loggeragent class added array of classes explicitly want manipulate.

    string[] includearr = new string[] { "java/math/bigdecimal" }; arraylist<string> include = new arraylist(arrays.aslist(includearr)); 
  2. in transform method of loggeragent class modified loop include classes explicitly want manipulate.

    for (int = 0; < ignore.length; i++) {     if (classname.startswith(ignore[i]) && !include.contains(classname)) {                 return bytes;     } } 
  3. fixed method methodreturnsvalue of javassisthelper correctly distinguish between methods , constructors.

    private static boolean methodreturnsvalue(ctbehavior method)throws notfoundexception {      if (method instanceof ctmethod){         ctclass returntype = ((ctmethod) method).getreturntype();         string returntypename = returntype.getname();         if(returntypename.equals("void")){             return false;         }else{             return true;         }         } else{         return false;     } } 
  4. last, in helloworld class created bigdecimal check manipulation behavior.

the output looks follow:

19/06/2015 16:00:26 java.math.bigdecimal signum info: << signum() returns: 1 19/06/2015 16:00:26 java.math.bigdecimal layoutchars info: << layoutchars(1=true) returns: 11.1099999999999994315658113919198513031005859375 19/06/2015 16:00:26 java.math.bigdecimal tostring info: << tostring() returns: 11.1099999999999994315658113919198513031005859375 19/06/2015 16:00:26 com.runjva.demo.helloworld main info: << main(args=[]) bigdecimal=11.1099999999999994315658113919198513031005859375 stop @ fri jun 19 16:00:26 pdt 2015 

i hope helps. if not, please add more details of trying do.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -