retrieve line number information
authorjowenn <none@none>
Sat, 6 Mar 2004 17:27:56 +0000 (17:27 +0000)
committerjowenn <none@none>
Sat, 6 Mar 2004 17:27:56 +0000 (17:27 +0000)
global.h
jit/jit.c
jit/jit.h
jit/parse.c
loader.c
src/vm/global.h
src/vm/jit/jit.c
src/vm/jit/jit.h
src/vm/jit/parse.c
src/vm/loader.c

index cd3d90bb19f81a57c9182df02ffd4889f13f3fed..d9cf9dd712e9bb8e9ffd5bca20a2e5574ce45a31 100644 (file)
--- a/global.h
+++ b/global.h
@@ -31,7 +31,7 @@
             Philipp Tomsich
                        Edwin Steiner
 
-   $Id: global.h 940 2004-03-06 14:04:15Z jowenn $
+   $Id: global.h 941 2004-03-06 17:27:56Z jowenn $
 
 */
 
@@ -195,6 +195,7 @@ typedef struct vftbl vftbl;
 typedef u1* methodptr;
 typedef struct fieldinfo  fieldinfo; 
 typedef struct methodinfo methodinfo; 
+typedef struct lineinfo lineinfo; 
 typedef struct arraydescriptor arraydescriptor;
 
 
@@ -545,6 +546,12 @@ typedef struct xtainfo {
 } xtainfo; 
 
 
+/* lineinfo *****************************************************************/
+struct lineinfo {
+       u2 start_pc;
+       u2 line_number;
+};
+
 /* methodinfo *****************************************************************/
 
 struct methodinfo {                 /* method structure                       */
@@ -566,11 +573,13 @@ struct methodinfo {                 /* method structure                       */
        u1        *jcode;               /* pointer to JavaVM code                 */
 
        s4         exceptiontablelength;/* exceptiontable length                  */
-       exceptiontable *exceptiontable; 
+       exceptiontable *exceptiontable; /* the exceptiontable                     */
+
+       u2      thrownexceptionscount; /*number of exceptions declared to be thrown by a method*/
+       classinfo **thrownexceptions;  /*array of classinfos of declared exceptions*/
 
-       u2      thrownexceptionscount;
-       classinfo **thrownexceptions;
-                                    /* the exceptiontable                     */
+       u2      linenumbercount;        /*number of linenumber attributes*/
+       lineinfo *linenumbers;          /*array of lineinfo items (start_pc,line_number)*/
 
        u1        *stubroutine;         /* stub for compiling or calling natives  */    
        s4         mcodelength;         /* legth of generated machine code        */
index 12dd4bc1290f4290298ae39e791b52c8ee9c1ed3..47a42cafad1c305cc86e98a252a6c2c8938041d7 100644 (file)
--- a/jit/jit.c
+++ b/jit/jit.c
@@ -29,7 +29,7 @@
 
    Changes: Edwin Steiner
 
-   $Id: jit.c 923 2004-02-24 13:28:08Z edwin $
+   $Id: jit.c 941 2004-03-06 17:27:56Z jowenn $
 
 */
 
@@ -153,6 +153,8 @@ int maxstack;                   /* maximal JavaVM stack size                  */
 int maxlocals;                  /* maximal number of local JavaVM variables   */
 int jcodelength;                /* length of JavaVM-codes                     */
 u1 *jcode;                      /* pointer to start of JavaVM-code            */
+lineinfo *jlinenumbers;                /* line information array                     */
+u2 jlinenumbercount;           /* number of entries in the linenumber array  */
 int exceptiontablelength;       /* length of exception table                  */
 xtable *extable;                /* pointer to start of exception table        */
 exceptiontable *raw_extable;
@@ -1517,6 +1519,8 @@ methodptr jit_compile(methodinfo *m)
        maxlocals = m->maxlocals;
        jcodelength = m->jcodelength;
        jcode = m->jcode;
+       jlinenumbers = m->linenumbers;
+       jlinenumbercount = m->linenumbercount;
        exceptiontablelength = m->exceptiontablelength;
        raw_extable = m->exceptiontable;
        regs_ok = false;
index c59ba67bab468d7c4a081a22c19318d77c304d0f..d72017db9875fe578c93eb29a078db4f25c1e477 100644 (file)
--- a/jit/jit.h
+++ b/jit/jit.h
@@ -29,7 +29,7 @@
 
    Changes: Christian Thalinger
 
-   $Id: jit.h 938 2004-03-06 00:56:43Z twisti $
+   $Id: jit.h 941 2004-03-06 17:27:56Z jowenn $
 
 */
 
@@ -110,9 +110,10 @@ struct instruction {
        u2  opc;                    /* opcode of intermediate code command        */
        s4  op1;                    /* first operand, usually variable number     */
        imm_union val;              /* immediate constant                         */
-       void *target;                           /* used for targets of branches and jumps         */
-                                                               /* and as address for list of targets for         */
-                                                               /* statements                                                             */
+       void *target;                   /* used for targets of branches and jumps         */
+                                       /* and as address for list of targets for         */
+                                       /* statements                                   */
+       u2 line                         /* line number in source file */
 };
 
 
@@ -895,6 +896,8 @@ extern int maxstack;            /* maximal JavaVM stack size                  */
 extern int maxlocals;           /* maximal number of local JavaVM variables   */
 extern int jcodelength;         /* length of JavaVM-codes                     */
 extern u1 *jcode;               /* pointer to start of JavaVM-code            */
+lineinfo *jlinenumbers;         /* line information array                     */
+u2 jlinenumbercount;            /* number of entries in the linenumber array  */
 extern int exceptiontablelength;/* length of exception table                  */
 extern xtable *extable;         /* pointer to start of exception table        */
 extern exceptiontable *raw_extable;
index 3f0687611addb93c90851def42fca94fcc4a1b59..93cb649e9e79a1d1fd2d032647a2f4cab4122dc8 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Carolyn Oates
             Edwin Steiner
 
-   $Id: parse.c 893 2004-01-19 12:53:24Z edwin $
+   $Id: parse.c 941 2004-03-06 17:27:56Z jowenn $
 
 */
 
@@ -344,13 +344,13 @@ void descriptor2types(methodinfo *m)
 #define OP(o)          iptr->opc=(o);/*iptr->op1=0*/;/*iptr->val.l=0*/;PINC
 #define OP1(o,o1)      iptr->opc=(o);iptr->op1=(o1);/*iptr->val.l=(0)*/;PINC
 #define OP2I(o,o1,v)   iptr->opc=(o);iptr->op1=(o1);iptr->val.i=(v);PINC
-#define OP2A(o,o1,v)   iptr->opc=(o);iptr->op1=(o1);iptr->val.a=(v);PINC
-#define BUILTIN1(v,t)  isleafmethod=false;iptr->opc=ICMD_BUILTIN1;iptr->op1=t;\
-                       iptr->val.a=(v);PINC
-#define BUILTIN2(v,t)  isleafmethod=false;iptr->opc=ICMD_BUILTIN2;iptr->op1=t;\
-                       iptr->val.a=(v);PINC
-#define BUILTIN3(v,t)  isleafmethod=false;iptr->opc=ICMD_BUILTIN3;iptr->op1=t;\
-                       iptr->val.a=(v);PINC
+#define OP2A(o,o1,v,l)   iptr->opc=(o);iptr->op1=(o1);iptr->val.a=(v);iptr->line=l;PINC
+#define BUILTIN1(v,t,l)  isleafmethod=false;iptr->opc=ICMD_BUILTIN1;iptr->op1=t;\
+                       iptr->val.a=(v);iptr->line=l;PINC
+#define BUILTIN2(v,t,l)  isleafmethod=false;iptr->opc=ICMD_BUILTIN2;iptr->op1=t;\
+                       iptr->val.a=(v);iptr->line=l;PINC
+#define BUILTIN3(v,t,l)  isleafmethod=false;iptr->opc=ICMD_BUILTIN3;iptr->op1=t;\
+                       iptr->val.a=(v);iptr->line=l;PINC
 
 /* We have to check local variables indices here because they are
  * used in stack.c to index the locals array. */
@@ -471,6 +471,10 @@ void parse()
        xtable* nextex;             /* points next free entry in extable          */
        u1 *instructionstart;       /* 1 for pcs which are valid instr. starts    */
 
+       u2 lineindex=0;
+       u2 currentline=0;
+       u2 linepcchange=0;
+
        bool useinltmp;
 
        if (compileverbose) {
@@ -588,14 +592,31 @@ void parse()
 #endif
 
        /* scan all java instructions */
+       currentline=0;
+       linepcchange=0;
+       if (jlinenumbercount==0) {
+               lineindex=0;
+       } else {
+               linepcchange=jlinenumbers[0].start_pc;
+       }
 
        for (p = 0, gp = 0; p < jcodelength; gp += (nextp - p), p = nextp) {
          
                /* DEBUG */       /*printf("p:%d gp:%d ",p,gp);*/
 
                /* mark this position as a valid instruction start */
-               if (!iswide)
+               if (!iswide) {
                        instructionstart[p] = 1;
+                       if (linepcchange==p) {
+                               if (jlinenumbercount>lineindex) {
+                                       currentline=jlinenumbers[lineindex].line_number;
+                                       lineindex++;
+                                       if (lineindex<jlinenumbercount)
+                                               linepcchange=jlinenumbers[lineindex].start_pc;
+/*                                     printf("Line number changed to: %ld\n",currentline);*/
+                               }
+                       }
+               }
 
                /*INLINING*/
                if ((useinlining) && (gp == nextgp)) {
@@ -882,28 +903,28 @@ void parse()
                        OP2I(ICMD_CHECKASIZE, 0, 0);
                        switch (code_get_s1(p + 1)) {
                        case 4:
-                               BUILTIN1(BUILTIN_newarray_boolean, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_boolean, TYPE_ADR,currentline);
                                break;
                        case 5:
-                               BUILTIN1(BUILTIN_newarray_char, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_char, TYPE_ADR,currentline);
                                break;
                        case 6:
-                               BUILTIN1(BUILTIN_newarray_float, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_float, TYPE_ADR,currentline);
                                break;
                        case 7:
-                               BUILTIN1(BUILTIN_newarray_double, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_double, TYPE_ADR,currentline);
                                break;
                        case 8:
-                               BUILTIN1(BUILTIN_newarray_byte, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_byte, TYPE_ADR,currentline);
                                break;
                        case 9:
-                               BUILTIN1(BUILTIN_newarray_short, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_short, TYPE_ADR,currentline);
                                break;
                        case 10:
-                               BUILTIN1(BUILTIN_newarray_int, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_int, TYPE_ADR,currentline);
                                break;
                        case 11:
-                               BUILTIN1(BUILTIN_newarray_long, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_long, TYPE_ADR,currentline);
                                break;
                        default: panic("Invalid array-type to create");
                        }
@@ -918,7 +939,7 @@ void parse()
 
                                s_count++;
 
-                               BUILTIN2(BUILTIN_newarray, TYPE_ADR);
+                               BUILTIN2(BUILTIN_newarray, TYPE_ADR,currentline);
                        }
                        break;
 
@@ -928,7 +949,7 @@ void parse()
                        {
                                int v = code_get_u1(p + 3);
                                vftbl *arrayvftbl = ((classinfo*)class_getconstant (class, i, CONSTANT_Class))->vftbl;
-                               OP2A(opcode, v, arrayvftbl);                    
+                               OP2A(opcode, v, arrayvftbl,currentline);                        
                        }
                        break;
 
@@ -1038,7 +1059,7 @@ void parse()
                                        tablep = DMNEW(s4, num * 2 + 2);
                                }
 
-                               OP2A(opcode, 0, tablep);
+                               OP2A(opcode, 0, tablep,currentline);
 
                                /* default target */
 
@@ -1108,7 +1129,7 @@ void parse()
                                        tablep = DMNEW(s4, num + 1 + 3);
                                }
 
-                               OP2A(opcode, 0, tablep);
+                               OP2A(opcode, 0, tablep,currentline);
 
                                /* default target */
 
@@ -1160,7 +1181,7 @@ void parse()
                        /* load and store of object fields *******************/
 
                case JAVA_AASTORE:
-                       BUILTIN3(BUILTIN_aastore, TYPE_VOID);
+                       BUILTIN3(BUILTIN_aastore, TYPE_VOID,currentline);
                        break;
 
                case JAVA_PUTSTATIC:
@@ -1171,7 +1192,7 @@ void parse()
                                fieldinfo *fi;
                                fr = class_getconstant(class, i, CONSTANT_Fieldref);
                                fi = class_findfield(fr->class, fr->name, fr->descriptor);
-                               OP2A(opcode, fi->type, fi);
+                               OP2A(opcode, fi->type, fi,currentline);
                                if (!fi->class->initialized) {
                                        isleafmethod = false;
                                }
@@ -1186,7 +1207,7 @@ void parse()
                                fieldinfo *fi;
                                fr = class_getconstant (class, i, CONSTANT_Fieldref);
                                fi = class_findfield (fr->class, fr->name, fr->descriptor);
-                               OP2A(opcode, fi->type, fi);
+                               OP2A(opcode, fi->type, fi,currentline);
                        }
                        break;
 
@@ -1211,7 +1232,7 @@ void parse()
                                descriptor2types(mi);
 
                                isleafmethod=false;
-                               OP2A(opcode, mi->paramcount, mi);
+                               OP2A(opcode, mi->paramcount, mi,currentline);
                        }
                        break;
 
@@ -1235,7 +1256,7 @@ void parse()
                                        panic ("Static/Nonstatic mismatch calling static method");
                                descriptor2types(mi);
                                isleafmethod=false;
-                               OP2A(opcode, mi->paramcount, mi);
+                               OP2A(opcode, mi->paramcount, mi,currentline);
                        }
                        break;
 
@@ -1251,7 +1272,7 @@ void parse()
                                        panic ("Static/Nonstatic mismatch calling static method");
                                descriptor2types(mi);
                                isleafmethod=false;
-                               OP2A(opcode, mi->paramcount, mi);
+                               OP2A(opcode, mi->paramcount, mi,currentline);
                        }
                        break;
 
@@ -1262,7 +1283,7 @@ void parse()
 
                        LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
                        s_count++;
-                       BUILTIN1(BUILTIN_new, TYPE_ADR);
+                       BUILTIN1(BUILTIN_new, TYPE_ADR,currentline);
                        break;
 
                case JAVA_CHECKCAST:
@@ -1276,15 +1297,15 @@ void parse()
                                                /* array type cast-check */
                                                LOADCONST_A_BUILTIN(cls->vftbl);
                                                s_count++;
-                                               BUILTIN2(BUILTIN_checkarraycast, TYPE_ADR);
+                                               BUILTIN2(BUILTIN_checkarraycast, TYPE_ADR,currentline);
                                        }
                                        else { /* object type cast-check */
                                                /*
 +                                                LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
 +                                                s_count++;
-+                                                BUILTIN2(BUILTIN_checkcast, TYPE_ADR);
++                                                BUILTIN2(BUILTIN_checkcast, TYPE_ADR,currentline);
 +                                              */
-                                               OP2A(opcode, 1, cls);
+                                               OP2A(opcode, 1, cls,currentline);
                                        }
                                }
 
@@ -1302,15 +1323,15 @@ void parse()
                                                /* array type cast-check */
                                                LOADCONST_A_BUILTIN(cls->vftbl);
                                                s_count++;
-                                               BUILTIN2(BUILTIN_arrayinstanceof, TYPE_INT);
+                                               BUILTIN2(BUILTIN_arrayinstanceof, TYPE_INT,currentline);
                                        }
                                        else { /* object type cast-check */
                                                /*
                                                  LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
                                                  s_count++;
-                                                 BUILTIN2(BUILTIN_instanceof, TYPE_INT);
+                                                 BUILTIN2(BUILTIN_instanceof, TYPE_INT,currentline);
 +                                              */
-                                               OP2A(opcode, 1, cls);
+                                               OP2A(opcode, 1, cls,currentline);
                                        }
                                }
                        break;
@@ -1318,7 +1339,7 @@ void parse()
                case JAVA_MONITORENTER:
 #ifdef USE_THREADS
                        if (checksync) {
-                               BUILTIN1(BUILTIN_monitorenter, TYPE_VOID);
+                               BUILTIN1(BUILTIN_monitorenter, TYPE_VOID,currentline);
                        } else
 #endif
                                {
@@ -1329,7 +1350,7 @@ void parse()
                case JAVA_MONITOREXIT:
 #ifdef USE_THREADS
                        if (checksync) {
-                               BUILTIN1(BUILTIN_monitorexit, TYPE_VOID);
+                               BUILTIN1(BUILTIN_monitorexit, TYPE_VOID,currentline);
                        }
                        else
 #endif
@@ -1360,7 +1381,7 @@ void parse()
 #if defined(__I386__)
                        OP(opcode);
 #else
-                       BUILTIN2(BUILTIN_frem, TYPE_FLOAT);
+                       BUILTIN2(BUILTIN_frem, TYPE_FLOAT,currentline);
 #endif
                        break;
 
@@ -1368,14 +1389,14 @@ void parse()
 #if defined(__I386__)
                        OP(opcode);
 #else
-                       BUILTIN2(BUILTIN_drem, TYPE_DOUBLE);
+                       BUILTIN2(BUILTIN_drem, TYPE_DOUBLE,currentline);
 #endif
                        break;
 
                case JAVA_F2I:
 #if defined(__ALPHA__)
                        if (!opt_noieee) {
-                               BUILTIN1(BUILTIN_f2i, TYPE_INT);
+                               BUILTIN1(BUILTIN_f2i, TYPE_INT,currentline);
                        } else
 #endif
                                {
@@ -1386,7 +1407,7 @@ void parse()
                case JAVA_F2L:
 #if defined(__ALPHA__)
                        if (!opt_noieee) {
-                               BUILTIN1(BUILTIN_f2l, TYPE_LONG);
+                               BUILTIN1(BUILTIN_f2l, TYPE_LONG,currentline);
                        } else 
 #endif
                                {
@@ -1397,7 +1418,7 @@ void parse()
                case JAVA_D2I:
 #if defined(__ALPHA__)
                        if (!opt_noieee) {
-                               BUILTIN1(BUILTIN_d2i, TYPE_INT);
+                               BUILTIN1(BUILTIN_d2i, TYPE_INT,currentline);
                        } else
 #endif
                                {
@@ -1408,7 +1429,7 @@ void parse()
                case JAVA_D2L:
 #if defined(__ALPHA__)
                        if (!opt_noieee) {
-                               BUILTIN1(BUILTIN_d2l, TYPE_LONG);
+                               BUILTIN1(BUILTIN_d2l, TYPE_LONG,currentline);
                        } else
 #endif
                                {
index fadb17cc21e1b03caf2cb95c34e8967bc52c92dc..a258a085fe0a933190b08731644a4eded48e44f9 100644 (file)
--- a/loader.c
+++ b/loader.c
@@ -30,7 +30,7 @@
             Mark Probst
                        Edwin Steiner
 
-   $Id: loader.c 940 2004-03-06 14:04:15Z jowenn $
+   $Id: loader.c 941 2004-03-06 17:27:56Z jowenn $
 
 */
 
@@ -86,6 +86,7 @@ static utf *utf_innerclasses;                 /* InnerClasses            */
 static utf *utf_constantvalue;                 /* ConstantValue           */
 static utf *utf_code;                      /* Code                    */
 static utf *utf_exceptions;            /* Exceptions                    */
+static utf *utf_linenumbertable;               /* LineNumberTable                    */
 static utf *utf_finalize;                  /* finalize                */
 static utf *utf_fidesc;                    /* ()V changed             */
 static utf *utf_init;                          /* <init>                  */
@@ -1047,6 +1048,8 @@ static void method_load(methodinfo *m, classinfo *c)
        count_all_methods++;
 #endif
        m->thrownexceptionscount=0;
+       m->linenumbercount=0;
+       m->linenumbers=0;
        m->class = c;
        
        m->flags = suck_u2();
@@ -1183,8 +1186,28 @@ static void method_load(methodinfo *m, classinfo *c)
                                      class_getconstant(c, idx, CONSTANT_Class);
                                }
                        }                       
-
-                       skipattributes(suck_u2());
+                       {
+                               u2 codeattrnum;
+                               for (codeattrnum=suck_u2();codeattrnum>0;codeattrnum--) {
+                                       utf * caname = class_getconstant(c, suck_u2(), CONSTANT_Utf8);
+                                       if (caname==utf_linenumbertable) {
+                                               u2 lncid;
+                                               /*log_text("LineNumberTable found");*/
+                                               suck_u4();
+                                               m->linenumbercount=suck_u2();
+                                               /*printf("length:%d\n",m->linenumbercount);*/
+                                               m->linenumbers=MNEW(lineinfo,m->linenumbercount);
+                                               for (lncid=0;lncid<m->linenumbercount;lncid++) {
+                                                       m->linenumbers[lncid].start_pc=suck_u2();
+                                                       m->linenumbers[lncid].line_number=suck_u2();
+                                               }
+                                               codeattrnum--;
+                                               skipattributes(codeattrnum);
+                                               break;
+                                       } else skipattributebody();
+                                       
+                               }                               
+                       }
                }
        }
 
@@ -3755,6 +3778,7 @@ void loader_init(u1 *stackbottom)
        utf_constantvalue   = utf_new_char("ConstantValue");
        utf_code                = utf_new_char("Code");
        utf_exceptions          = utf_new_char("Exceptions");
+       utf_linenumbertable     = utf_new_char("LineNumberTable");
        utf_finalize        = utf_new_char("finalize");
        utf_fidesc              = utf_new_char("()V");
        utf_init                = utf_new_char("<init>");
index cd3d90bb19f81a57c9182df02ffd4889f13f3fed..d9cf9dd712e9bb8e9ffd5bca20a2e5574ce45a31 100644 (file)
@@ -31,7 +31,7 @@
             Philipp Tomsich
                        Edwin Steiner
 
-   $Id: global.h 940 2004-03-06 14:04:15Z jowenn $
+   $Id: global.h 941 2004-03-06 17:27:56Z jowenn $
 
 */
 
@@ -195,6 +195,7 @@ typedef struct vftbl vftbl;
 typedef u1* methodptr;
 typedef struct fieldinfo  fieldinfo; 
 typedef struct methodinfo methodinfo; 
+typedef struct lineinfo lineinfo; 
 typedef struct arraydescriptor arraydescriptor;
 
 
@@ -545,6 +546,12 @@ typedef struct xtainfo {
 } xtainfo; 
 
 
+/* lineinfo *****************************************************************/
+struct lineinfo {
+       u2 start_pc;
+       u2 line_number;
+};
+
 /* methodinfo *****************************************************************/
 
 struct methodinfo {                 /* method structure                       */
@@ -566,11 +573,13 @@ struct methodinfo {                 /* method structure                       */
        u1        *jcode;               /* pointer to JavaVM code                 */
 
        s4         exceptiontablelength;/* exceptiontable length                  */
-       exceptiontable *exceptiontable; 
+       exceptiontable *exceptiontable; /* the exceptiontable                     */
+
+       u2      thrownexceptionscount; /*number of exceptions declared to be thrown by a method*/
+       classinfo **thrownexceptions;  /*array of classinfos of declared exceptions*/
 
-       u2      thrownexceptionscount;
-       classinfo **thrownexceptions;
-                                    /* the exceptiontable                     */
+       u2      linenumbercount;        /*number of linenumber attributes*/
+       lineinfo *linenumbers;          /*array of lineinfo items (start_pc,line_number)*/
 
        u1        *stubroutine;         /* stub for compiling or calling natives  */    
        s4         mcodelength;         /* legth of generated machine code        */
index 12dd4bc1290f4290298ae39e791b52c8ee9c1ed3..47a42cafad1c305cc86e98a252a6c2c8938041d7 100644 (file)
@@ -29,7 +29,7 @@
 
    Changes: Edwin Steiner
 
-   $Id: jit.c 923 2004-02-24 13:28:08Z edwin $
+   $Id: jit.c 941 2004-03-06 17:27:56Z jowenn $
 
 */
 
@@ -153,6 +153,8 @@ int maxstack;                   /* maximal JavaVM stack size                  */
 int maxlocals;                  /* maximal number of local JavaVM variables   */
 int jcodelength;                /* length of JavaVM-codes                     */
 u1 *jcode;                      /* pointer to start of JavaVM-code            */
+lineinfo *jlinenumbers;                /* line information array                     */
+u2 jlinenumbercount;           /* number of entries in the linenumber array  */
 int exceptiontablelength;       /* length of exception table                  */
 xtable *extable;                /* pointer to start of exception table        */
 exceptiontable *raw_extable;
@@ -1517,6 +1519,8 @@ methodptr jit_compile(methodinfo *m)
        maxlocals = m->maxlocals;
        jcodelength = m->jcodelength;
        jcode = m->jcode;
+       jlinenumbers = m->linenumbers;
+       jlinenumbercount = m->linenumbercount;
        exceptiontablelength = m->exceptiontablelength;
        raw_extable = m->exceptiontable;
        regs_ok = false;
index c59ba67bab468d7c4a081a22c19318d77c304d0f..d72017db9875fe578c93eb29a078db4f25c1e477 100644 (file)
@@ -29,7 +29,7 @@
 
    Changes: Christian Thalinger
 
-   $Id: jit.h 938 2004-03-06 00:56:43Z twisti $
+   $Id: jit.h 941 2004-03-06 17:27:56Z jowenn $
 
 */
 
@@ -110,9 +110,10 @@ struct instruction {
        u2  opc;                    /* opcode of intermediate code command        */
        s4  op1;                    /* first operand, usually variable number     */
        imm_union val;              /* immediate constant                         */
-       void *target;                           /* used for targets of branches and jumps         */
-                                                               /* and as address for list of targets for         */
-                                                               /* statements                                                             */
+       void *target;                   /* used for targets of branches and jumps         */
+                                       /* and as address for list of targets for         */
+                                       /* statements                                   */
+       u2 line                         /* line number in source file */
 };
 
 
@@ -895,6 +896,8 @@ extern int maxstack;            /* maximal JavaVM stack size                  */
 extern int maxlocals;           /* maximal number of local JavaVM variables   */
 extern int jcodelength;         /* length of JavaVM-codes                     */
 extern u1 *jcode;               /* pointer to start of JavaVM-code            */
+lineinfo *jlinenumbers;         /* line information array                     */
+u2 jlinenumbercount;            /* number of entries in the linenumber array  */
 extern int exceptiontablelength;/* length of exception table                  */
 extern xtable *extable;         /* pointer to start of exception table        */
 extern exceptiontable *raw_extable;
index 3f0687611addb93c90851def42fca94fcc4a1b59..93cb649e9e79a1d1fd2d032647a2f4cab4122dc8 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Carolyn Oates
             Edwin Steiner
 
-   $Id: parse.c 893 2004-01-19 12:53:24Z edwin $
+   $Id: parse.c 941 2004-03-06 17:27:56Z jowenn $
 
 */
 
@@ -344,13 +344,13 @@ void descriptor2types(methodinfo *m)
 #define OP(o)          iptr->opc=(o);/*iptr->op1=0*/;/*iptr->val.l=0*/;PINC
 #define OP1(o,o1)      iptr->opc=(o);iptr->op1=(o1);/*iptr->val.l=(0)*/;PINC
 #define OP2I(o,o1,v)   iptr->opc=(o);iptr->op1=(o1);iptr->val.i=(v);PINC
-#define OP2A(o,o1,v)   iptr->opc=(o);iptr->op1=(o1);iptr->val.a=(v);PINC
-#define BUILTIN1(v,t)  isleafmethod=false;iptr->opc=ICMD_BUILTIN1;iptr->op1=t;\
-                       iptr->val.a=(v);PINC
-#define BUILTIN2(v,t)  isleafmethod=false;iptr->opc=ICMD_BUILTIN2;iptr->op1=t;\
-                       iptr->val.a=(v);PINC
-#define BUILTIN3(v,t)  isleafmethod=false;iptr->opc=ICMD_BUILTIN3;iptr->op1=t;\
-                       iptr->val.a=(v);PINC
+#define OP2A(o,o1,v,l)   iptr->opc=(o);iptr->op1=(o1);iptr->val.a=(v);iptr->line=l;PINC
+#define BUILTIN1(v,t,l)  isleafmethod=false;iptr->opc=ICMD_BUILTIN1;iptr->op1=t;\
+                       iptr->val.a=(v);iptr->line=l;PINC
+#define BUILTIN2(v,t,l)  isleafmethod=false;iptr->opc=ICMD_BUILTIN2;iptr->op1=t;\
+                       iptr->val.a=(v);iptr->line=l;PINC
+#define BUILTIN3(v,t,l)  isleafmethod=false;iptr->opc=ICMD_BUILTIN3;iptr->op1=t;\
+                       iptr->val.a=(v);iptr->line=l;PINC
 
 /* We have to check local variables indices here because they are
  * used in stack.c to index the locals array. */
@@ -471,6 +471,10 @@ void parse()
        xtable* nextex;             /* points next free entry in extable          */
        u1 *instructionstart;       /* 1 for pcs which are valid instr. starts    */
 
+       u2 lineindex=0;
+       u2 currentline=0;
+       u2 linepcchange=0;
+
        bool useinltmp;
 
        if (compileverbose) {
@@ -588,14 +592,31 @@ void parse()
 #endif
 
        /* scan all java instructions */
+       currentline=0;
+       linepcchange=0;
+       if (jlinenumbercount==0) {
+               lineindex=0;
+       } else {
+               linepcchange=jlinenumbers[0].start_pc;
+       }
 
        for (p = 0, gp = 0; p < jcodelength; gp += (nextp - p), p = nextp) {
          
                /* DEBUG */       /*printf("p:%d gp:%d ",p,gp);*/
 
                /* mark this position as a valid instruction start */
-               if (!iswide)
+               if (!iswide) {
                        instructionstart[p] = 1;
+                       if (linepcchange==p) {
+                               if (jlinenumbercount>lineindex) {
+                                       currentline=jlinenumbers[lineindex].line_number;
+                                       lineindex++;
+                                       if (lineindex<jlinenumbercount)
+                                               linepcchange=jlinenumbers[lineindex].start_pc;
+/*                                     printf("Line number changed to: %ld\n",currentline);*/
+                               }
+                       }
+               }
 
                /*INLINING*/
                if ((useinlining) && (gp == nextgp)) {
@@ -882,28 +903,28 @@ void parse()
                        OP2I(ICMD_CHECKASIZE, 0, 0);
                        switch (code_get_s1(p + 1)) {
                        case 4:
-                               BUILTIN1(BUILTIN_newarray_boolean, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_boolean, TYPE_ADR,currentline);
                                break;
                        case 5:
-                               BUILTIN1(BUILTIN_newarray_char, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_char, TYPE_ADR,currentline);
                                break;
                        case 6:
-                               BUILTIN1(BUILTIN_newarray_float, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_float, TYPE_ADR,currentline);
                                break;
                        case 7:
-                               BUILTIN1(BUILTIN_newarray_double, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_double, TYPE_ADR,currentline);
                                break;
                        case 8:
-                               BUILTIN1(BUILTIN_newarray_byte, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_byte, TYPE_ADR,currentline);
                                break;
                        case 9:
-                               BUILTIN1(BUILTIN_newarray_short, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_short, TYPE_ADR,currentline);
                                break;
                        case 10:
-                               BUILTIN1(BUILTIN_newarray_int, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_int, TYPE_ADR,currentline);
                                break;
                        case 11:
-                               BUILTIN1(BUILTIN_newarray_long, TYPE_ADR);
+                               BUILTIN1(BUILTIN_newarray_long, TYPE_ADR,currentline);
                                break;
                        default: panic("Invalid array-type to create");
                        }
@@ -918,7 +939,7 @@ void parse()
 
                                s_count++;
 
-                               BUILTIN2(BUILTIN_newarray, TYPE_ADR);
+                               BUILTIN2(BUILTIN_newarray, TYPE_ADR,currentline);
                        }
                        break;
 
@@ -928,7 +949,7 @@ void parse()
                        {
                                int v = code_get_u1(p + 3);
                                vftbl *arrayvftbl = ((classinfo*)class_getconstant (class, i, CONSTANT_Class))->vftbl;
-                               OP2A(opcode, v, arrayvftbl);                    
+                               OP2A(opcode, v, arrayvftbl,currentline);                        
                        }
                        break;
 
@@ -1038,7 +1059,7 @@ void parse()
                                        tablep = DMNEW(s4, num * 2 + 2);
                                }
 
-                               OP2A(opcode, 0, tablep);
+                               OP2A(opcode, 0, tablep,currentline);
 
                                /* default target */
 
@@ -1108,7 +1129,7 @@ void parse()
                                        tablep = DMNEW(s4, num + 1 + 3);
                                }
 
-                               OP2A(opcode, 0, tablep);
+                               OP2A(opcode, 0, tablep,currentline);
 
                                /* default target */
 
@@ -1160,7 +1181,7 @@ void parse()
                        /* load and store of object fields *******************/
 
                case JAVA_AASTORE:
-                       BUILTIN3(BUILTIN_aastore, TYPE_VOID);
+                       BUILTIN3(BUILTIN_aastore, TYPE_VOID,currentline);
                        break;
 
                case JAVA_PUTSTATIC:
@@ -1171,7 +1192,7 @@ void parse()
                                fieldinfo *fi;
                                fr = class_getconstant(class, i, CONSTANT_Fieldref);
                                fi = class_findfield(fr->class, fr->name, fr->descriptor);
-                               OP2A(opcode, fi->type, fi);
+                               OP2A(opcode, fi->type, fi,currentline);
                                if (!fi->class->initialized) {
                                        isleafmethod = false;
                                }
@@ -1186,7 +1207,7 @@ void parse()
                                fieldinfo *fi;
                                fr = class_getconstant (class, i, CONSTANT_Fieldref);
                                fi = class_findfield (fr->class, fr->name, fr->descriptor);
-                               OP2A(opcode, fi->type, fi);
+                               OP2A(opcode, fi->type, fi,currentline);
                        }
                        break;
 
@@ -1211,7 +1232,7 @@ void parse()
                                descriptor2types(mi);
 
                                isleafmethod=false;
-                               OP2A(opcode, mi->paramcount, mi);
+                               OP2A(opcode, mi->paramcount, mi,currentline);
                        }
                        break;
 
@@ -1235,7 +1256,7 @@ void parse()
                                        panic ("Static/Nonstatic mismatch calling static method");
                                descriptor2types(mi);
                                isleafmethod=false;
-                               OP2A(opcode, mi->paramcount, mi);
+                               OP2A(opcode, mi->paramcount, mi,currentline);
                        }
                        break;
 
@@ -1251,7 +1272,7 @@ void parse()
                                        panic ("Static/Nonstatic mismatch calling static method");
                                descriptor2types(mi);
                                isleafmethod=false;
-                               OP2A(opcode, mi->paramcount, mi);
+                               OP2A(opcode, mi->paramcount, mi,currentline);
                        }
                        break;
 
@@ -1262,7 +1283,7 @@ void parse()
 
                        LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
                        s_count++;
-                       BUILTIN1(BUILTIN_new, TYPE_ADR);
+                       BUILTIN1(BUILTIN_new, TYPE_ADR,currentline);
                        break;
 
                case JAVA_CHECKCAST:
@@ -1276,15 +1297,15 @@ void parse()
                                                /* array type cast-check */
                                                LOADCONST_A_BUILTIN(cls->vftbl);
                                                s_count++;
-                                               BUILTIN2(BUILTIN_checkarraycast, TYPE_ADR);
+                                               BUILTIN2(BUILTIN_checkarraycast, TYPE_ADR,currentline);
                                        }
                                        else { /* object type cast-check */
                                                /*
 +                                                LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
 +                                                s_count++;
-+                                                BUILTIN2(BUILTIN_checkcast, TYPE_ADR);
++                                                BUILTIN2(BUILTIN_checkcast, TYPE_ADR,currentline);
 +                                              */
-                                               OP2A(opcode, 1, cls);
+                                               OP2A(opcode, 1, cls,currentline);
                                        }
                                }
 
@@ -1302,15 +1323,15 @@ void parse()
                                                /* array type cast-check */
                                                LOADCONST_A_BUILTIN(cls->vftbl);
                                                s_count++;
-                                               BUILTIN2(BUILTIN_arrayinstanceof, TYPE_INT);
+                                               BUILTIN2(BUILTIN_arrayinstanceof, TYPE_INT,currentline);
                                        }
                                        else { /* object type cast-check */
                                                /*
                                                  LOADCONST_A_BUILTIN(class_getconstant(class, i, CONSTANT_Class));
                                                  s_count++;
-                                                 BUILTIN2(BUILTIN_instanceof, TYPE_INT);
+                                                 BUILTIN2(BUILTIN_instanceof, TYPE_INT,currentline);
 +                                              */
-                                               OP2A(opcode, 1, cls);
+                                               OP2A(opcode, 1, cls,currentline);
                                        }
                                }
                        break;
@@ -1318,7 +1339,7 @@ void parse()
                case JAVA_MONITORENTER:
 #ifdef USE_THREADS
                        if (checksync) {
-                               BUILTIN1(BUILTIN_monitorenter, TYPE_VOID);
+                               BUILTIN1(BUILTIN_monitorenter, TYPE_VOID,currentline);
                        } else
 #endif
                                {
@@ -1329,7 +1350,7 @@ void parse()
                case JAVA_MONITOREXIT:
 #ifdef USE_THREADS
                        if (checksync) {
-                               BUILTIN1(BUILTIN_monitorexit, TYPE_VOID);
+                               BUILTIN1(BUILTIN_monitorexit, TYPE_VOID,currentline);
                        }
                        else
 #endif
@@ -1360,7 +1381,7 @@ void parse()
 #if defined(__I386__)
                        OP(opcode);
 #else
-                       BUILTIN2(BUILTIN_frem, TYPE_FLOAT);
+                       BUILTIN2(BUILTIN_frem, TYPE_FLOAT,currentline);
 #endif
                        break;
 
@@ -1368,14 +1389,14 @@ void parse()
 #if defined(__I386__)
                        OP(opcode);
 #else
-                       BUILTIN2(BUILTIN_drem, TYPE_DOUBLE);
+                       BUILTIN2(BUILTIN_drem, TYPE_DOUBLE,currentline);
 #endif
                        break;
 
                case JAVA_F2I:
 #if defined(__ALPHA__)
                        if (!opt_noieee) {
-                               BUILTIN1(BUILTIN_f2i, TYPE_INT);
+                               BUILTIN1(BUILTIN_f2i, TYPE_INT,currentline);
                        } else
 #endif
                                {
@@ -1386,7 +1407,7 @@ void parse()
                case JAVA_F2L:
 #if defined(__ALPHA__)
                        if (!opt_noieee) {
-                               BUILTIN1(BUILTIN_f2l, TYPE_LONG);
+                               BUILTIN1(BUILTIN_f2l, TYPE_LONG,currentline);
                        } else 
 #endif
                                {
@@ -1397,7 +1418,7 @@ void parse()
                case JAVA_D2I:
 #if defined(__ALPHA__)
                        if (!opt_noieee) {
-                               BUILTIN1(BUILTIN_d2i, TYPE_INT);
+                               BUILTIN1(BUILTIN_d2i, TYPE_INT,currentline);
                        } else
 #endif
                                {
@@ -1408,7 +1429,7 @@ void parse()
                case JAVA_D2L:
 #if defined(__ALPHA__)
                        if (!opt_noieee) {
-                               BUILTIN1(BUILTIN_d2l, TYPE_LONG);
+                               BUILTIN1(BUILTIN_d2l, TYPE_LONG,currentline);
                        } else
 #endif
                                {
index fadb17cc21e1b03caf2cb95c34e8967bc52c92dc..a258a085fe0a933190b08731644a4eded48e44f9 100644 (file)
@@ -30,7 +30,7 @@
             Mark Probst
                        Edwin Steiner
 
-   $Id: loader.c 940 2004-03-06 14:04:15Z jowenn $
+   $Id: loader.c 941 2004-03-06 17:27:56Z jowenn $
 
 */
 
@@ -86,6 +86,7 @@ static utf *utf_innerclasses;                 /* InnerClasses            */
 static utf *utf_constantvalue;                 /* ConstantValue           */
 static utf *utf_code;                      /* Code                    */
 static utf *utf_exceptions;            /* Exceptions                    */
+static utf *utf_linenumbertable;               /* LineNumberTable                    */
 static utf *utf_finalize;                  /* finalize                */
 static utf *utf_fidesc;                    /* ()V changed             */
 static utf *utf_init;                          /* <init>                  */
@@ -1047,6 +1048,8 @@ static void method_load(methodinfo *m, classinfo *c)
        count_all_methods++;
 #endif
        m->thrownexceptionscount=0;
+       m->linenumbercount=0;
+       m->linenumbers=0;
        m->class = c;
        
        m->flags = suck_u2();
@@ -1183,8 +1186,28 @@ static void method_load(methodinfo *m, classinfo *c)
                                      class_getconstant(c, idx, CONSTANT_Class);
                                }
                        }                       
-
-                       skipattributes(suck_u2());
+                       {
+                               u2 codeattrnum;
+                               for (codeattrnum=suck_u2();codeattrnum>0;codeattrnum--) {
+                                       utf * caname = class_getconstant(c, suck_u2(), CONSTANT_Utf8);
+                                       if (caname==utf_linenumbertable) {
+                                               u2 lncid;
+                                               /*log_text("LineNumberTable found");*/
+                                               suck_u4();
+                                               m->linenumbercount=suck_u2();
+                                               /*printf("length:%d\n",m->linenumbercount);*/
+                                               m->linenumbers=MNEW(lineinfo,m->linenumbercount);
+                                               for (lncid=0;lncid<m->linenumbercount;lncid++) {
+                                                       m->linenumbers[lncid].start_pc=suck_u2();
+                                                       m->linenumbers[lncid].line_number=suck_u2();
+                                               }
+                                               codeattrnum--;
+                                               skipattributes(codeattrnum);
+                                               break;
+                                       } else skipattributebody();
+                                       
+                               }                               
+                       }
                }
        }
 
@@ -3755,6 +3778,7 @@ void loader_init(u1 *stackbottom)
        utf_constantvalue   = utf_new_char("ConstantValue");
        utf_code                = utf_new_char("Code");
        utf_exceptions          = utf_new_char("Exceptions");
+       utf_linenumbertable     = utf_new_char("LineNumberTable");
        utf_finalize        = utf_new_char("finalize");
        utf_fidesc              = utf_new_char("()V");
        utf_init                = utf_new_char("<init>");