Ejemplo n.º 1
0
Pixel32 colorStringToColor(const UTF8String& s)
{
    int r, g, b;
    int numChars;
    int numItems = sscanf(s.c_str(), "%2x%2x%2x%n", &r, &g, &b, &numChars);
    if (s.length() != 6 || numChars != 6 || numItems != 3) {
        throw(Exception (AVG_ERR_INVALID_ARGS, "colorstring cannot be parsed."));
    }
    return Pixel32(r, g, b);
}
Ejemplo n.º 2
0
   void VTune_RegisterMethod(AvmCore* core, JITCodeInfo* inf) 
   {       
		// assume no method inlining so start/end of JIT code gen = method start/end
       uintptr startAt = inf->startAddr;
       uintptr endAt = inf->endAddr;
		uint32 methodSize = endAt - startAt;

       Stringp name = inf->method->format(core);
       int idx[4];
       bool hasClass = locateNames(core, name, idx);

		// register the method
		iJIT_Method_Load ML;
       Stringp mname = name->substring(idx[2],idx[3]);
		VMPI_memset(&ML, 0, sizeof(iJIT_Method_Load));
       ML.method_id = (inf->vtune) ? inf->vtune->method_id : iJIT_GetNewMethodID();
       ML.method_name = string2char(core, mname);
		ML.method_load_address = (void *)startAt;	// virtual address of that method  - This determines the method range for the iJVM_EVENT_TYPE_ENTER/LEAVE_METHOD_ADDR events
		ML.method_size = methodSize;	// Size in memory - Must be exact

		// md position / line number table
       SortedIntMap<LineNumberRecord*>* tbl = &inf->lineNumTable;
		int size = tbl->size();
		LineNumberInfo* lines = 0;
		if (size)
		{
			int bsz = size*sizeof(LineNumberInfo);
			lines = (LineNumberInfo*) malloc(bsz);
			VMPI_memset(lines, 0, bsz);
		}

       String* fileName = 0;
       int at = 0;
       for(int i=0; i<size; i++) 
		{
			sintptr mdPos = tbl->keyAt(i);
			LineNumberRecord* entry = tbl->at(i);
           if (entry->filename && entry->lineno)
           {
               if (!fileName) fileName = entry->filename;

               // @todo file name should be part of the lines[] record, no?
               lines[at].LineNumber = entry->lineno;
               lines[at].Offset = mdPos - startAt;
               at++;
           }
       }

       // @todo hack for vtune since it can't process multiple records with the same method name 
       if (inf->sid>0 && at>0) {
           mname = core->concatStrings(mname,core->newString("_L"));
           mname = core->concatStrings(mname,core->intToString(lines[0].LineNumber));
           mname = core->concatStrings(mname,core->newString("_"));
           mname = core->concatStrings(mname,core->intToString(inf->sid));
           if (ML.method_name) free(ML.method_name);
           ML.method_name = string2char(core,mname);
       }

       ML.line_number_table = lines;   // Pointer to the begining of the line numbers info array
       ML.line_number_size = at;       // Line Table size in number of entries - Zero if none

       UTF8String* utf = ( fileName ) ? fileName->toUTF8String() : core->kEmptyString->toUTF8String();
		
		ML.class_id = 0;                // uniq class ID
       ML.class_file_name = (hasClass) ? string2char(core,name->substring(idx[0],idx[1])) : 0;     // class file name 
		ML.source_file_name = (char *)(malloc((utf->length()+3)*sizeof(char)));   // +1 for \0 and +2 for wtoc's ()
		wtoc(ML.source_file_name, utf->c_str(), 0);	// source file name 

		ML.user_data = NULL;            // bits supplied by the user for saving in the JIT file...
		ML.user_data_size = 0;          // the size of the user data buffer
		ML.env = iJDE_JittingAPI;

		// DumpVTuneMethodInfo(core, &ML); // Uncommented to debug VTune
		iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, &ML);

       if (inf->vtune && core->VTuneStatus == iJIT_CALLGRAPH_ON) 
		{
			MMgc::GCHeap* heap = core->GetGC()->GetGCHeap();
           heap->SetPageProtection(inf->vtune, sizeof (iJIT_Method_NIDS), false, true);   
       }

		// free everything we alloc'd  ( @todo did vtune really copy all the strings?!? )
		if (ML.line_number_table) free(ML.line_number_table);
       if (ML.class_file_name && hasClass) free(ML.class_file_name);
		if (ML.method_name) free(ML.method_name);
		if (ML.source_file_name) free(ML.source_file_name);
	}	
Ejemplo n.º 3
0
Anything Anything::decodeJSON(const UTF8String& jsonstring, bool errorhandling) throw (IOException) 
{
	char* buffer = 0;
	struct JSON_parser_struct* jc = 0;

	try
	{
		char errbuf[512];

		JSON_config config;
		init_JSON_config(&config);

		Anything stack = new ListAnythingI(); 
		UTF8StringBuffer trace;
		if (errorhandling) trace->ensureCapacity(jsonstring->length());

		config.depth = -1;
		config.callback = &createAnythingCallback;
		config.callback_ctx = (void*) stack.get();
		config.allow_comments = 0;
		config.handle_floats_manually = 1;

		jc = new_JSON_parser(&config);

		int len = jsonstring->length() + 1;
		buffer = new char[len];
		strcpy(buffer, constcharptr(jsonstring));

		for (int i = 0; i < len; ++i) 
		{
			int nextchar = buffer[i];
			if (nextchar <= 0) break;
			if (!JSON_parser_char(jc, nextchar)) 
			{
				if (errorhandling) trace->append(" <-- syntax error\n");
				sprintf(errbuf, "JSON_parser_char: syntax error at position : %d", i);
				trace->append(errbuf);
				throw IOException(WITHDETAILS(String(trace->toString())));
			}
			if (errorhandling) trace->append((char) nextchar);
		}

		if (!JSON_parser_done(jc)) 
		{
			if (errorhandling) trace->append(" <-- syntax error\n");
			sprintf(errbuf, "JSON_parser_end: syntax error, not yet done.");
			trace->append(errbuf);
			throw IOException(WITHDETAILS(String(trace->toString())));
		}

		// cleanup
		delete_JSON_parser(jc);
		delete [] buffer;

		return pop(stack);
	}
	catch (const IOException&)
	{
		delete_JSON_parser(jc);
		delete [] buffer;
		throw;
	}
	catch (const Exception& e)
	{
		delete_JSON_parser(jc);
		delete [] buffer;
		throw IOException(e->toString());
	}
}