objArrayOop InterpretedIC::pic_array() { assert(send_type() == Bytecodes::polymorphic_send, "Must be a polymorphic send site"); objArrayOop result = objArrayOop(second_word()); assert(result->is_objArray(), "interpreter pic must be object array"); assert(result->length() >= 4, "pic should contain at least two entries"); return result; }
void InterpretedIC::clear() { if (is_empty()) return; if (send_type() == Bytecodes::polymorphic_send) { // recycle PIC assert(second_word()->is_objArray(), "must be a pic"); Interpreter_PICs::deallocate(objArrayOop(second_word())); } set(Bytecodes::original_send_code_for(send_code()), oop(selector()), smiOop_zero); }
void Classtable::on_pushButton_2_clicked() { NewClass *nc =new NewClass(this); connect(this,SIGNAL(send_type(int,int,int,QString)),nc,SLOT(rec_type(int,int,int,QString))); // connect(nc,SIGNAL(sendtable(Table,QList<Tutor>*,QList<Problem>*,QList<Email>*)),this,SLOT(rec_table(Table,QList<Tutor>*,QList<Problem>*,QList<Email>*))); //count=tutor->count(); emit send_type(i,j,2,ui->comboBox->currentText()); nc->show(); }
void InterpretedIC::replace(LookupResult result, klassOop receiver_klass) { // IC entries before modification - used for loging only Bytecodes::Code code_before = send_code(); oop word1_before = first_word(); oop word2_before = second_word(); int transition = 0; // modify IC guarantee(word2_before == receiver_klass, "klass should be the same"); if (result.is_empty()) { clear(); transition = 1; } else if (result.is_method()) { if (send_type() == Bytecodes::megamorphic_send) { set(send_code(), result.method(), receiver_klass); transition = 2; } else { // Please Fix this Robert // implement set_monomorphic(klass, method) clear(); transition = 3; } } else { if (send_type() == Bytecodes::megamorphic_send) { set(send_code(), oop(result.entry()), receiver_klass); transition = 4; } else { assert(result.is_entry(), "must be jump table entry"); // a jump table entry of a nmethod is found so let's update the current send set(Bytecodes::compiled_send_code_for(send_code()), oop(result.entry()), receiver_klass); transition = 5; } } // IC entries after modification - used for loging only Bytecodes::Code code_after = send_code(); oop word1_after = first_word(); oop word2_after = second_word(); // log modification LOG_EVENT3("InterpretedIC::replace: IC at 0x%x: entry for klass 0x%x replaced (transition %d)", this, receiver_klass, transition); LOG_EVENT3(" from (%s, 0x%x, 0x%x)", Bytecodes::name(code_before), word1_before, word2_before); LOG_EVENT3(" to (%s, 0x%x, 0x%x)", Bytecodes::name(code_after ), word1_after , word2_after ); }
void InterpretedIC::replace(nmethod* nm) { // replace entry with nm's klass by nm (if entry exists) smiOop entry_point = smiOop(nm->jump_table_entry()->entry_point()); assert(selector() == nm->key.selector(), "mismatched selector"); if (is_empty()) return; switch (send_type()) { case Bytecodes::accessor_send: // fall through case Bytecodes::primitive_send: // fall through case Bytecodes::predicted_send: // fall through case Bytecodes::interpreted_send: { // replace the monomorphic interpreted send with compiled send klassOop receiver_klass = klassOop(second_word()); assert(receiver_klass->is_klass(), "receiver klass must be a klass"); if (receiver_klass == nm->key.klass()) { set(Bytecodes::compiled_send_code_for(send_code()), entry_point, nm->key.klass()); } } break; case Bytecodes::compiled_send: // fall through case Bytecodes::megamorphic_send: // replace the monomorphic compiled send with compiled send set(send_code(), entry_point, nm->key.klass()); break; case Bytecodes::polymorphic_send: { objArrayOop pic = pic_array(); for (int index = pic->length(); index > 0; index -= 2) { klassOop receiver_klass = klassOop(pic->obj_at(index)); assert(receiver_klass->is_klass(), "receiver klass must be klass"); if (receiver_klass == nm->key.klass()) { pic->obj_at_put(index-1, entry_point); return; } } } // did not find klass break; default: fatal("unknown send type"); } LOG_EVENT3("interpreted IC at 0x%x: new nmethod 0x%x for klass 0x%x replaces old entry", this, nm, nm->key.klass()); }
void InterpretedIC::print() { std->print("Inline cache ("); if (is_empty()) { std->print("empty"); } else { std->print(Bytecodes::send_type_as_string(send_type())); } std->print(") "); selector()->print_value(); std->cr(); InterpretedIC_Iterator it(this); while (!it.at_end()) { std->print("\t- klass: "); it.klass()->print_value(); if (it.is_interpreted()) { std->print(";\tmethod %#x\n", it.interpreted_method()); } else { std->print(";\tnmethod %#x\n", it.compiled_method()); } it.advance(); } }
void InterpretedIC::cleanup() { if (is_empty()) return; // Nothing to cleanup switch (send_type()) { case Bytecodes::accessor_send: // fall through case Bytecodes::primitive_send: // fall through case Bytecodes::predicted_send: // fall through case Bytecodes::interpreted_send: { // check if the interpreted send should be replaced by a compiled send klassOop receiver_klass = klassOop(second_word()); assert(receiver_klass->is_klass(), "receiver klass must be a klass"); methodOop method = methodOop(first_word()); assert(method->is_method(), "first word in interpreter IC must be method"); if (!Bytecodes::is_super_send(send_code())) { // super sends cannot be handled since the sending method holder is unknown at this point. LookupKey key(receiver_klass, selector()); LookupResult result = lookupCache::lookup(&key); if (!result.matches(method)) { replace(result, receiver_klass); } } } break; case Bytecodes::compiled_send: { // check if the current compiled send is valid klassOop receiver_klass = klassOop(second_word()); assert(receiver_klass->is_klass(), "receiver klass must be a klass"); jumpTableEntry* entry = (jumpTableEntry*) first_word(); nmethod* nm = entry->method(); LookupResult result = lookupCache::lookup(&nm->key); if (!result.matches(nm)) { replace(result, receiver_klass); } } break; case Bytecodes::megamorphic_send: // Note that with the current definition of is_empty() // this will not be called for normal megamorphic sends // since they store only the selector. { klassOop receiver_klass = klassOop(second_word()); if (first_word()->is_smi()) { jumpTableEntry* entry = (jumpTableEntry*) first_word(); nmethod* nm = entry->method(); LookupResult result = lookupCache::lookup(&nm->key); if (!result.matches(nm)) { replace(result, receiver_klass); } } else { methodOop method = methodOop(first_word()); assert(method->is_method(), "first word in interpreter IC must be method"); if (!Bytecodes::is_super_send(send_code())) { // super sends cannot be handled since the sending method holder is unknown at this point. LookupKey key(receiver_klass, selector()); LookupResult result = lookupCache::lookup(&key); if (!result.matches(method)) { replace(result, receiver_klass); } } } } break; case Bytecodes::polymorphic_send: { // %implementation note: // when cleaning up we can always preserve the old pic since the // the only transitions are: // (compiled -> compiled) // (compiled -> interpreted) // (interpreted -> compiled) // in case of a super send we do not have to cleanup because // no nmethods are compiled for super sends. if (!Bytecodes::is_super_send(send_code())) { objArrayOop pic = pic_array(); for (int index = pic->length(); index > 0; index -= 2) { klassOop klass = klassOop(pic->obj_at(index)); assert(klass->is_klass(), "receiver klass must be klass"); oop first = pic->obj_at(index-1); if (first->is_smi()) { jumpTableEntry* entry = (jumpTableEntry*) first; nmethod* nm = entry->method(); LookupResult result = lookupCache::lookup(&nm->key); if (!result.matches(nm)) { pic->obj_at_put(index-1, result.value()); } } else { methodOop method = methodOop(first); assert(method->is_method(), "first word in interpreter IC must be method"); LookupKey key(klass, selector()); LookupResult result = lookupCache::lookup(&key); if (!result.matches(method)) { pic->obj_at_put(index-1, result.value()); } } } } } } }
jumpTableEntry* InterpretedIC::jump_table_entry() const { assert(send_type() == Bytecodes::compiled_send || send_type() == Bytecodes::megamorphic_send, "must be a compiled call"); assert(first_word()->is_smi(), "must be smi"); return (jumpTableEntry*) first_word(); }
int main(int argc, char* argv[]) { //---------------------- #ifndef DEBUG srand(time(NULL)); srand_sse(time(NULL)); #else srand(1); srand_sse(1111); #endif if (argc < 3) { printf("Usage: %s <scd file name> <port> \n", argv[0]); return -1; } int port = atoi(argv[2]); int connfd = server_init(port); if (connfd == -1) { printf("Something's wrong with the socket!\n"); return -1; } #define GARBLING #ifndef GARBLING server_close(connfd); return 0; #else //----------------------------------------- Garbling GarbledCircuit garbledCircuit; long i, j, cid; readCircuitFromFile(&garbledCircuit, argv[1]); printf("garbledCircuit.I[0] = %d\n", garbledCircuit.I[0]); int n = garbledCircuit.n; int g = garbledCircuit.g; int p = garbledCircuit.p; int m = garbledCircuit.m; int c = garbledCircuit.c; int e = n - g; int *garbler_inputs = (int *) malloc(sizeof(int) * (g) * c); block *inputLabels = (block *) malloc(sizeof(block) * 2 * n * c); block *initialDFFLable = (block *) malloc(sizeof(block) * 2 * p); block *outputLabels = (block *) malloc(sizeof(block) * 2 * m * c); printf("\n\ninputs:\n"); for (cid = 0; cid < c; cid++) { for (j = 0; j < g; j++) { garbler_inputs[cid * g + j] = rand() % 2; printf("%d ", garbler_inputs[cid * g + j]); } } printf("\n\n"); #ifndef DEBUG block R = randomBlock(); *((short *) (&R)) |= 1; #else block R = makeBlock((long )(-1), (long )(-1)); #endif uint8_t * rptr = (uint8_t*) &R; for (int i = 0; i < 16; i++) rptr[i] = 0xff; // *((short *) (&R)) |= 1; rptr[0] |= 1; createInputLabels(inputLabels, R, n * c); createInputLabels(initialDFFLable, R, p); ///--------------------------------------------------------------- OT Extension //Parameters int numOTs = c * e; int bitlength = 128; m_nSecParam = 128; m_nNumOTThreads = 1; BYTE version; crypto *crypt = new crypto(m_nSecParam, (uint8_t*) m_vSeed); InitOTSender(connfd, crypt); CBitVector delta, X1, X2; delta.Create(numOTs, bitlength, crypt); m_fMaskFct = new XORMasking(bitlength, delta); for (int i=0;i<numOTs;i++) delta.SetBytes(rptr, i*16, 16); printf("Delta: "); for (int i = 0; i < 16; i++) { printf("%02x", delta.GetByte(i)); } printf("\n"); printf("R: "); print__m128i(R); printf("\n"); X1.Create(numOTs, bitlength); X1.Reset(); X2.Create(numOTs, bitlength); X2.Reset(); uint8_t* b = new BYTE[16]; BYTE* b2 = new BYTE[16]; cout << "Sender performing " << numOTs << " C_OT extensions on " << bitlength << " bit elements" << endl; version = C_OT; ObliviouslySend(X1, X2, numOTs, bitlength, version, crypt); //putting X1 & X2 into inputLabels printf("printing inputLabels after copy from X1 and X2:\n\n"); uint8_t* inputLabelsptr; for (cid = 0; cid < c; cid++) { for (j = 0; j < e; j++) { inputLabelsptr = (uint8_t*) &inputLabels[2 * (cid * n + g + j)]; X1.GetBytes(inputLabelsptr, 16*(cid * e + j), 16); print__m128i(inputLabels[2 * (cid * n + g + j)]); inputLabelsptr = (uint8_t*) &inputLabels[2 * (cid * n + g + j) + 1]; X2.GetBytes(inputLabelsptr, 16*(cid * e + j), 16); print__m128i(inputLabels[2 * (cid * n + g + j) + 1]); } } //print printf("Printing X1:\n"); for (int j = 0; j < numOTs; j++) { for (int i = 0; i < 16; i++) { b[i] = X1.GetByte(i + j * 16); printf("%02x", b[i]); } printf("\n"); } printf("\n\n"); printf("Printing X2:\n"); for (int j = 0; j < numOTs; j++) { for (int i = 0; i < 16; i++) { b[i] = X2.GetByte(i + j * 16); printf("%02x", b[i]); } printf("\n"); } printf("\n\n"); printf("Printing delta:\t"); for (int i = 0; i < 16; i++) { b[i] = delta.GetByte(i); printf("%02x", b[i]); } printf("\n"); //----------------------------------------------------end of OT Extension for (cid = 0; cid < c; cid++) { for (j = 0; j < g; j++) { if (garbler_inputs[cid * g + j] == 0) send_block(connfd, inputLabels[2 * (cid * n + j)]); else send_block(connfd, inputLabels[2 * (cid * n + j) + 1]); printf("i(%ld, %ld, %d)\n", cid, j, garbler_inputs[cid * g + j]); print__m128i(inputLabels[2 * (cid * n + j)]); print__m128i(inputLabels[2 * (cid * n + j) + 1]); } //------------------------------------------------------------------------------------------ CHANGE 1 for (j = 0; j < e; j++) { // int ev_input; // read(connfd, &ev_input, sizeof(int)); // if (!ev_input) // send_block(connfd, inputLabels[2 * (cid * n + g + j)]); // else // send_block(connfd, inputLabels[2 * (cid * n + g + j) + 1]); printf("evaluator : i(%ld, %ld, ?)\n", cid, j); print__m128i(inputLabels[2 * (cid * n + g + j)]); print__m128i(inputLabels[2 * (cid * n + g + j) + 1]); } printf("Compare to: "); printf("\n"); //----------------------------------------------------------------------end } printf("\n\n"); for (j = 0; j < p; j++) //p:#DFF { printf("garbledCircuit.I[j] = %d\n", garbledCircuit.I[j]); if (garbledCircuit.I[j] == CONST_ZERO) // constant zero { send_block(connfd, initialDFFLable[2 * j]); printf("dffi(%ld, %ld, %d)\n", cid, j, 0); print__m128i(initialDFFLable[2 * j]); print__m128i(initialDFFLable[2 * j + 1]); } else if (garbledCircuit.I[j] == CONST_ONE) // constant zero { send_block(connfd, initialDFFLable[2 * j + 1]); printf("dffi(%ld, %ld, %d)\n", cid, j, 0); print__m128i(inputLabels[2 * j]); print__m128i(inputLabels[2 * j + 1]); } else if (garbledCircuit.I[j] < g) //belongs to Alice (garbler) { int index = garbledCircuit.I[j]; if (garbler_inputs[index] == 0) send_block(connfd, initialDFFLable[2 * j]); else send_block(connfd, initialDFFLable[2 * j + 1]); printf("dffi(%ld, %ld, %d)\n", cid, j, garbler_inputs[index]); print__m128i(initialDFFLable[2 * j]); print__m128i(initialDFFLable[2 * j + 1]); } //------------------------------------------------------------------------------------------ CHANGE 2 else //**** belongs to Bob { // int ev_input; // read(connfd, &ev_input, sizeof(int)); // if (!ev_input) // send_block(connfd, initialDFFLable[2 * j]); // else // send_block(connfd, initialDFFLable[2 * j + 1]); // printf("dffi(%ld, %ld, %d)\n", cid, j, ev_input); print__m128i(initialDFFLable[2 * j]); print__m128i(initialDFFLable[2 * j + 1]); printf("\n"); } //----------------------------------------------------------------------end } printf("\n\n"); ///--------------------------------------------------------------- OT Extension //Parameters numOTs = p; delta.Create(numOTs, bitlength, crypt); m_fMaskFct = new XORMasking(bitlength, delta); for (int i=0;i<numOTs;i++) delta.SetBytes(rptr, i*16, 16); printf("Delta: "); for (int i = 0; i < 16; i++) { printf("%02x", delta.GetByte(i)); } printf("\n"); printf("R: "); print__m128i(R); printf("\n"); X1.Create(numOTs, bitlength); X1.Reset(); X2.Create(numOTs, bitlength); X2.Reset(); cout << "Sender performing " << numOTs << " C_OT extensions on " << bitlength << " bit elements" << endl; version = C_OT; ObliviouslySend(X1, X2, numOTs, bitlength, version, crypt); //putting X1 & X2 into inputLabels printf("printing inputLabels after copy from X1 and X2:\n\n"); for (j = 0; j < p; j++) { inputLabelsptr = (uint8_t*) &initialDFFLable[2 * j]; X1.GetBytes(inputLabelsptr, 16*(j), 16); inputLabelsptr = (uint8_t*) &initialDFFLable[2 * j +1]; X2.GetBytes(inputLabelsptr, 16*( j), 16); } delete crypt; //----------------------------------------------------end of OT Extension garbledCircuit.globalKey = randomBlock(); send_block(connfd, garbledCircuit.globalKey); // send DKC key printf("R: "); print__m128i(R); printf("\n"); garble(&garbledCircuit, inputLabels, initialDFFLable, outputLabels, &R, connfd); printf("***************** InputLabels\n"); for (int i=0;i<n*c*2;i++) print__m128i(inputLabels[i]); for (cid = 0; cid < c; cid++) { for (i = 0; i < m; i++) { short outputType = getLSB(outputLabels[2 * (m * cid + i) + 0]); send_type(connfd, outputType); } } server_close(connfd); removeGarbledCircuit(&garbledCircuit); return 0; #endif }