File: method.c

package info (click to toggle)
jmp 0.48-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,692 kB
  • ctags: 1,732
  • sloc: ansic: 13,985; sh: 8,611; makefile: 526; yacc: 318; java: 18
file content (192 lines) | stat: -rw-r--r-- 4,977 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <jvmpi.h>
#include <translate.h>

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <method.h>
#include <cls.h>
#include <mvector.h>

method* method_new (const char* method_name, char* method_signature, 
		    jint start_lineno, jint end_lineno,
		    jmethodID method_id, cls* owner) {
    char* buf;
    method* m;
    size_t l1, l2, l3;
    
    /* initialize each field to zero... */
    m = calloc (1, sizeof (*m));
    if (m == NULL)
	return NULL;
    l1 = strlen (method_name) + 1;
    l2 = strlen (method_signature) + 1;

    buf = calloc (10000, 1);
    translate_method (method_name, method_signature, buf);
    l3 = strlen (buf) + 1;
    
    m->method_name = malloc (l1);
    m->method_signature = malloc (l2);
    m->jmpname = malloc (l3);
    m->called_methods = mvector_new (5);
    m->callee_methods = mvector_new (5);
    if (m->method_name == NULL ||
	m->method_signature == NULL ||
	m->jmpname == NULL ||
	m->called_methods == NULL || 
	m->callee_methods == NULL) {
	method_free (m);
	return NULL;
    }
    strncpy (m->method_name, method_name, l1);
    strncpy (m->method_signature, method_signature, l2);
    strncpy (m->jmpname, buf, l3);
    free (buf);
    m->start_lineno = start_lineno;
    m->end_lineno = end_lineno;
    m->method_id = method_id;
    m->owner = owner;
    return m;
}

void method_free (method* m) {
    if (m == NULL)
	return;
    free (m->method_name);
    m->method_name = NULL;
    free (m->method_signature);
    m->method_signature = NULL;
    free (m->jmpname);
    m->jmpname = NULL;
    mvector_free (m->called_methods);
    m->called_methods = NULL;
    mvector_free (m->callee_methods);
    m->callee_methods = NULL;
    free (m);
}

size_t method_jmphash_func (void* c, size_t len) {
    method* mp = (method*)c;
    return ((long)mp->method_id) % len;
}

int method_cmp_func (void* c1, void* c2) {
    method* m1 = (method*)c1;
    method* m2 = (method*)c2;;
    return m1->method_id != m2->method_id;
}

void method_print (method* m) {
    fprintf (stdout, "    %s (%s), %d -> %d, %p\n", 
	     m->method_name, m->method_signature,
	     m->start_lineno, m->end_lineno, 
	     m->method_id);    
}

inline void method_set_method_id (method* m, jmethodID method_id) {
    m->method_id = method_id;
}

inline jmethodID method_get_method_id (const method* m) {
    return m->method_id;
}

inline char* method_get_method_name (method* m) {
    return m->method_name;
}

inline char* method_get_method_signature (method* m) {
    return m->method_signature;
}

inline char* method_get_method_jmpname (method* m) {
    return m->jmpname;
}

inline jobjectID method_get_class_id (method* m) {
    return cls_get_class_id (m->owner);
}

inline unsigned method_get_entered (method* m) {
    return m->entered;
}

inline long method_get_calls (method* m) {
    return m->calls;
}

inline long method_get_restore_calls (method* m) {
    return m->restore_calls;
}

inline methodtime* method_get_time_used (method* m) {
    return &m->time_used;
}

inline methodtime* method_get_restore_time (method* m) {
    return &m->restore_time;
}

inline cls* method_get_owner (method* m) {
    return m->owner;
}

inline void method_reset_count (method* m) {
    m->restore_calls += m->calls;
    m->calls = 0;
    m->restore_time.tv += m->time_used.tv;
    m->time_used.tv = 0;
    m->restore_time.tv_hold += m->time_used.tv_hold;
    m->time_used.tv_hold = 0;
    m->restore_objects += m->allocated_objects;
    m->allocated_objects = 0;
    m->restore_memory += m->allocated_memory;
    m->allocated_memory = 0;
    m->modified = 1;
}

inline void method_restore_count (method* m) {
    m->calls += m->restore_calls;
    m->restore_calls = 0;
    m->time_used.tv += m->restore_time.tv;
    m->restore_time.tv = 0;
    m->time_used.tv_hold += m->restore_time.tv_hold;
    m->restore_time.tv_hold = 0;
    m->allocated_objects += m->restore_objects;
    m->restore_objects = 0;
    m->allocated_memory += m->restore_memory;
    m->restore_memory = 0;
    m->modified = 1;
}

inline int method_check_modified (method* m) {
    return m->modified;
}

inline void method_set_modified (method* m, int flag) {
    m->modified = flag;
}

/** Returns the number of objects allocated by this method */
inline int method_get_allocated_objects (method* m) {
    return m->allocated_objects;
}

/** Returns the number of bytes used for allocating objects by this method */
inline jlong method_get_allocated_memory (method* m) {
    return m->allocated_memory;
}

/* Emacs Local Variables: */
/* Emacs mode:C */
/* Emacs c-indentation-style:"gnu" */
/* Emacs c-hanging-braces-alist:((brace-list-open)(brace-entry-open)(defun-open after)(substatement-open after)(block-close . c-snug-do-while)(extern-lang-open after)) */
/* Emacs c-cleanup-list:(brace-else-brace brace-elseif-brace space-before-funcall) */
/* Emacs c-basic-offset:4 */
/* Emacs End: */